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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
michaelsh
Kudo Kingpin
Kudo Kingpin

Table shows irrelevant values from "many" side of one-to-many relation

I have Invoices table that is connected to SalesOrders tables with many-to-one relation.

(There could be multiple Invoices connected to one Sales Order, there also can be Sales Orders without any invoice)

The simple star-schema is below.

Also, here is the link to .pbix:

https://1drv.ms/u/s!AoP_9ampPIT7gZUVjqRfj-CcNU7I_w?e=6fK5hG

I want to show a simple table (or matrix without sub-totals) showing the following:

Sales Order, SO Amt, Invoice Number, Invoice Amt

If I do a simple SO Amt = SUM('Sales Orders'[SO Amount]) then for each SO it shows all the unrelated invoices (see the left side of powerbi screenshot)

I tried to do a measure: SO Amt (isfiltered) =

IF(ISFILTERED(Invoices),BLANK(),SUM('Sales Orders'[SO Amount]))
But then, only subtotals are shown correctly.
I do want the SO Count and SO Amt to repeat but only for related invoices and I don't want to show subtotals.
Below is the layout I want.
Please help
Thanks

michaelsh_0-1622195854203.png

 

yesCapture.PNGnotCapture.PNG

 

1 ACCEPTED SOLUTION
michaelsh
Kudo Kingpin
Kudo Kingpin

Ok, I think I've solved this (after two beers...)

If any one finds a more elegant solution - please let me know...

Here is the solution file: 

https://1drv.ms/u/s!AoP_9ampPIT7gZUavYdk3iSFw8A7Vw?e=OMCJJd

I had to add a "dummy" invoice "No Invoices", so it shows instead of blanks

the measure is:

SO Amt solved =
VAR SOInvInd = IF(ISBLANK(CALCULATE( MAX(Invoices[Invoice Number]),all(Invoices[Invoice Number]))),FALSE(),TRUE()) //true if SO has an Invoice
VAR NoInv = IF(CALCULATE(SELECTEDVALUE(Invoices[Invoice Number]),ALL('Sales Orders'))="No Invoices",TRUE(),false()) //true if current line is No Invoice
return
SWITCH(TRUE(),
NOT(ISFILTERED(Invoices)),[SO Amt],
SOInvInd,CALCULATE([SO Amt],Invoices),
NoInv,[SO Amt],
BLANK()
)
 
michaelsh_0-1622208018962.png

 

View solution in original post

1 REPLY 1
michaelsh
Kudo Kingpin
Kudo Kingpin

Ok, I think I've solved this (after two beers...)

If any one finds a more elegant solution - please let me know...

Here is the solution file: 

https://1drv.ms/u/s!AoP_9ampPIT7gZUavYdk3iSFw8A7Vw?e=OMCJJd

I had to add a "dummy" invoice "No Invoices", so it shows instead of blanks

the measure is:

SO Amt solved =
VAR SOInvInd = IF(ISBLANK(CALCULATE( MAX(Invoices[Invoice Number]),all(Invoices[Invoice Number]))),FALSE(),TRUE()) //true if SO has an Invoice
VAR NoInv = IF(CALCULATE(SELECTEDVALUE(Invoices[Invoice Number]),ALL('Sales Orders'))="No Invoices",TRUE(),false()) //true if current line is No Invoice
return
SWITCH(TRUE(),
NOT(ISFILTERED(Invoices)),[SO Amt],
SOInvInd,CALCULATE([SO Amt],Invoices),
NoInv,[SO Amt],
BLANK()
)
 
michaelsh_0-1622208018962.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.