Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
FrankNY007
Frequent Visitor

How to count numbers based on related tables(tow tables)

Hello, 

 

I have three tables, there is a simple structure:

Image 21.jpg

 

Main table is B.

so i want to count how many shipment id in table b that have been marked as "Y" in C, but not beed marked as EDR in table A(has no record in table A).

 

in the screenshot, you can see shipment id 2, although it has reconrd in C, but since it has reconrd in A, so it won't be count 

 

like count(b.shipment.id) where(c.early_flag="Y" and isubll(b.munu_option))

9 REPLIES 9
Seward12533
Solution Sage
Solution Sage

As long as you have those relationship you can either just build a matrix or other visual of a measure that counts shipments from table B adn with Early Menu_Option and EarlyFlag in teh colums or filtered on the visual

 

Or write a DAX Measure using CALCULATE function with FILTER

 

Number Shipped Not EDR = CALCULATE(DISTINCTCOUNT(B[Shipment ID]),FILTER(C,C[Early Flag])="Y"),FILTER(A,A[Menu_Option]<>"EDR"))

 

 

 

i got null.

 

it is becasue of inner join?

 

the table C supposed have more records than A

drewlewis15
Solution Specialist
Solution Specialist

Count = CALCULATE(DISTINCTCOUNT('Table B'[Shipmend ID]), 'Table A'[Menu_Option] <> "EDR", 'Table C'[Early Flag] = "Y")

it gives me null

 

Early = CALCULATE(DISTINCTCOUNT('Order'[SALE_ID]),Airclic[EARLY_FLAG]="Y",EDR[MENU_OPTION]<>"EDR")

 

it is becaue of inner join?

@FrankNY007 Did you try with the explicit FILTER function in the calculate?

 

Number Shipped Not EDR = CALCULATE(DISTINCTCOUNT(B[Shipment ID]),FILTER(C,C[Early Flag])="Y"),FILTER(A,A[Menu_Option]<>"EDR"))

i found a way to fix the probem, but don't know why.

 

the problem is table A may have mutiple EDR for same shipment ID. so B to A is 1:M relationship.

 

when you put A.Menu_Option and B.Shipment ID in a same table, It only give you B.shipment ID that has the reocrd in table A, so all the non-record ID is disappread.(seems like inner join)

 

BUT B and C is 1:1, so when you Put B. Shipment ID with C.Early_Flag.

 

it give all every ID, even it doen't marked as Y in table C

Is it working or not?  There are ways to handle it but woudl need more information.  

 

TIP if the DAX gets too messy or confusing you could build your own summary tables dynamically using DAX and then relate them.

 

To create an bridge table for ShipmentIDs

ShipmentIDs = VALUES(A[Shipment_ID])

Then you could create a Summary table of Shipment_IDs with counts for each menu option (or just EDR)

 

A_EDR = CALCULATE(SUMMARIZE(A,[ShipmentID],"Count",COUNTROWS(A)),A[MENU_Option]="EDR")

You could also do this in power query by creating a new query REFERENCED from the one use to generate A and then Pivot it in Power Query so you end up with a 1:1 table.

 

 

Once you have summary table(s) and bridge tables you can relate them in yoru model and do calculations.

i put B.shiment ID, A.Menu_Option, C. Early_Flag

 

it give me a table only for ID both has menu_option and early_flag, becasue it default i inner join? 

 

when you filter the table by menu_option<>"EDR", it returns blank table.

Stilll no.

 

think about is you only use 

 

Early = CALCULATE(DISTINCTCOUNT('Order'[SALE_ID]),EDR[MENU_OPTION]="EDR",Airclic[EARLY_FLAG]="Y")

 

it give me 54, this is all shipment that both EDR and Early_Flag="Y"

 

the problem is:

 

in the table for EDR, my query only give me all shipment has EDR, when you filter EDR[MENU_OPTION]<>"EDR", you got a empty table!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.