# 11.4 Relationships समजून बनवा

Source: https://ravindrabagale.com/mr/powerbi/ch11-data-modelling/11-4-relationships.html
Language: mr (Marathi with English technical terms)

Autodetect नावं व types पाहून relationship बनवू शकतो; तो नेहमी योग्य असेलच असं नाही. Model view किंवा Modeling › Manage relationships तपासा. Key एका table वरून matching key वर drag करा किंवा Manage relationships › New वापरा.

 | Cardinality | अर्थ | उदाहरण

 | 1:* | Dimension ची एक row अनेक fact rows शी | Product → Orders

 | *:1 | तीच जोडणी उलट बाजूने | Orders → Product

 | 1:1 | दोन्ही keys unique | Employee आणि Employee Details; merge योग्य असू शकतो

 | *:* | दोन्हीकडे repeats | Orders व city-month targets; grain mismatch काळजीपूर्वक हाताळा

Line च्या टोकांवर 1 आणि * दिसतात.

Cross-filter direction

Single: one side कडून many side कडे. Product[Category] = Snacks निवडलं की Orders filter होतात. Both: दोन्हीकडे flow; कधी आवश्यक, पण ambiguous paths, अनपेक्षित results आणि performance अडचणी येऊ शकतात.

साधारण Single ठेवा. एका measure पुरता वेगळा flow हवा तर CALCULATE मध्ये CROSSFILTER वापरण्याचा विचार करा. Slicer साठी [Total Sales] is not blank असा visual filterही काही cases मध्ये उपयोगी.

Active आणि inactive dates

Date → Orders[Order Date] active solid line; Date → Orders[Delivered Date] inactive dotted line. 11:55 pm ची order midnight नंतर deliver होऊ शकते, म्हणून दोन्ही dates वेगळ्या असतात.

Sales by Delivered Date =
CALCULATE(
    [Total Sales],
    USERELATIONSHIP(Orders[Delivered Date], 'Date'[Date])
)

USERELATIONSHIP measure मध्ये inactive date relationship वापरतो. दुसरा पर्याय म्हणजे वेगळी Delivered Date role-playing dimension; वापर आणि model size विचारात घ्या.

Relationship dialog

Line double-click करून cardinality, cross-filter direction, active status, RLS साठी Apply security filter in both directions आणि DirectQuery मधलं Assume referential integrity तपासा. Referential integrity खरंच हमीशीर असेल तेव्हाच inner-join optimization निवडा.

रवींद्र बागले यांची tip

Slicer मधलं Blank हे unmatched fact keysचं लक्षण असू शकतं. नवीन Store ID dimension मध्ये missing आहे का पाहा. Blank filter करून problem लपवण्याऐवजी key / dimension दुरुस्त करा.
