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
marcofalzone
Helper I
Helper I

Wrong Column Totals (Matrix)

I wrote a DAX measure that convert a YTD balance to a common currency (EUR). The measure works well when a single company is selected (1 currency) but generates a wrong Total column when I try to select 2 or more companies (currencies).

 

 

Act_Eur_Ytd = 
VAR NUMERATOR = [Act_Lc_Ytd]
VAR DENUMERATOR = CALCULATE(AVERAGE('Facts'[Avg_Ytd_Fx_Rate]), ENDOFMONTH('Calendar_Table'[Date].[Date]))
RETURN ROUND(DIVIDE(NUMERATOR,DENUMERATOR),2)

 

 

Example:

Screenshot_1.jpg

The expected output of the matrix is:

 

Screenshot_2.jpg

 

 

 

 

 

 

 

The current behavior of measure Act_Eur_Ytd is:

When Company 1 alone is selected, Numerator properly sums EUR amounts and divides them by 1

When Company 2 alone is selected, Numerator properly sums CNY amounts and divides them by 0.1

When both companies are selected, Numerator sums EUR + CNY (wrong) and divides by an average (wrong).

 

The exchange rate is linked to calendar, in order to convert at the latest average rate of the selected Month/Year.

In order to give a better context, I attach the real life example, with source data.

 

DOWNLOAD:

Example (pbix) and Source Data (xlsx) 

 

I appreciate the help of the community to properly correct the syntax of my DAX measure.

Thank you.

Marco 

 

 

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

Hi , @marcofalzone 

Thanks for your provided sample .pbix file .

According to your description, the total is wrong because it not get the summation of the columns.

You can try to use this measure :

Act_Eur_Ytd Test = 
var _t =ADDCOLUMNS( CROSSJOIN(VALUES('Company'[CompanyString]), VALUES('PL_Mapping'[PLRowDescr])) , "Act_Eur_Ytd" , [Act_Eur_Ytd])
return
SUMX(_t ,[Act_Eur_Ytd])

Then we can get the right total:

vyueyunzhmsft_0-1673314394618.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @marcofalzone 

Thanks for your provided sample .pbix file .

According to your description, the total is wrong because it not get the summation of the columns.

You can try to use this measure :

Act_Eur_Ytd Test = 
var _t =ADDCOLUMNS( CROSSJOIN(VALUES('Company'[CompanyString]), VALUES('PL_Mapping'[PLRowDescr])) , "Act_Eur_Ytd" , [Act_Eur_Ytd])
return
SUMX(_t ,[Act_Eur_Ytd])

Then we can get the right total:

vyueyunzhmsft_0-1673314394618.png

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

 

Dear Aniya, I'm really impressed by the quality and elegance of your solution. My congratulations for your skills! That's just what I was looking for.

I do appreciate the help that this community gives to whoever wants to learn and deep dive into SQL, DAX, and Business Intelligence challenges in general.

Thank you very much for your extremely VALUABLE support!
Marco - Mexico

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.

Top Solution Authors