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
bbzzbb808
New Member

Incorrect Measure Total on Matrix Visual

Hi,

 

I have the following the following report page with a date slicer and a table.

 

bbzzbb808_0-1712356666666.png

- The date slicer comes from a date table that DOES NOT have a relationship with my facts table. 

-The "Max" date in the date slicer is used for the "Calculation" measure (DAX below), which essentially is a SWITCH Function that handles the following conditions.

 

1) If "End Date" <= "Max" date in the date slicer then return the full value of "Dollars"
2) If "Start Date" = "Max" date in the date slicer then return daily rate of "Dollars" (Dollars / (End Date - Start Date)

3) If "End Date" > "Max" date in the date slicer then return the daily rate * ("Max" date in the date slicer - Start Date)

 

Calculation Dax

 SWITCH(
                TRUE(),
                MAX('Fact Table'[End Date]) <= MAX('3.dim_date_table'[Date]),
                SUM('Fact Table'[Dollars]),
                MAX('Fact Table'[Start Date]) = MAX('3.dim_date_table'[Date]),
                DIVIDE(SUM('Fact Table'[Dollars]),(DATEDIFF(MAX('Fact Table'[Start Date]),MAX('Fact Table'[End Date]),DAY)),0),
                MAX('Fact Table'[End Date]) > MAX('3.dim_date_table'[Date]),
                DIVIDE(SUM('Fact Table'[Dollars]),(DATEDIFF(MAX('Fact Table'[Start Date]),MAX('Fact Table'[End Date]),DAY)),0)*DATEDIFF(MAX('Fact Table'[Start Date]),MAX('3.dim_date_table'[Date])+1,DAY)
                ,
                0
            )
 
On a row by row basis, everything appears to be working as expected. The only issue is that the total amount is not accuate.
 
For example in the screenshot below, we see that the Calculation total is $5,934.01 when it should be $6,319.61
bbzzbb808_1-1712357011237.png

 

I suspect this is due to the lack of row context when referring to the "Max" start and "end" dates for the total calculations, so the max values of the entire dataset are used rather than calculating row by row.


Here is a link to the pbix file: https://drive.google.com/drive/folders/1GjFTpaLMW-6vf36LFPpHR_IHuhtaAcPL?usp=sharing

 

Please let me know if any additional information is needed. Any input is appreciated. Thanks!


1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @bbzzbb808 ,

 

Thanks for the reply from @DataNinja777 , please allow me to provide another insight:  

You can using the following measure.

Measure =
SUMX(
    VALUES('Fact Table'[ID]),[Calculation])

vyangliumsft_0-1712555332974.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
bbzzbb808
New Member

Thank you both! Appreciate the help

v-yangliu-msft
Community Support
Community Support

Hi  @bbzzbb808 ,

 

Thanks for the reply from @DataNinja777 , please allow me to provide another insight:  

You can using the following measure.

Measure =
SUMX(
    VALUES('Fact Table'[ID]),[Calculation])

vyangliumsft_0-1712555332974.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

DataNinja777
Super User
Super User

Hi @bbzzbb808 

You can get the correct total of the rows in the visual by using Sumx function.  Sumxing Calculation dax over the ID field will get you the correct total you are after. 

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.