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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
emiliePowerBI
New Member

Sum of DAX

Good Morning,

I have a DAX to convert my costs from local currency to EUR. This conversion should depend on the period, year and scenaripo selected using filters.

 

This DAX (test) is the results of 2 DAX: 

test = [ACTYTD]/[FX Rate] 
where: 
ACTYTD = TOTALYTD(SUM('ABC Master'[LC]),Dates[Date],'ABC Master'[Scenario]="Actual")
and 
FX Rate =
CALCULATE (
    SUMX (
        FILTER (
            'FX Table',
            'FX Table'[Date] <= MAX ( Dates[Date] ) && 'FX Table'[Date] >= STARTOFMONTH ( Dates[Date] )
        ),
        'FX Table'[FX Rate]
    ),
    'FX Table'[Scenario] = SELECTEDVALUE ( 'FX Table'[Scenario] )
)
 
The DAX "test " by row works really well.
 
Here are my tables connection:
emiliePowerBI_0-1730688480669.png

I would like the conversion to move according to the year, the scenario and the Month. We should be able to filter on Any brands in any country

emiliePowerBI_1-1730688657621.png

My problem is that the total of my "Test" is not correct. It seems tricky to calculate a sum of measure being the results of 2 DAX already.

 

I tried to create a bridge table but this is not working

ACTYTDEUR =
CALCULATE(
    SUMX('ABC Master',
        [ACTYTD] / [FX Rate])
    ,
    'Bridge'[Scenario] = SELECTEDVALUE('FX Table'[Scenario]),
    'Bridge'[Year] = SELECTEDVALUE('FX Table'[Year]),
    'Bridge'[Country code] = SELECTEDVALUE('FX Table'[Country code]),
    'Bridge'[Brand] = SELECTEDVALUE('ABC Master'[Brands])
)
 
I don't know if it is because of the links between my tables but they are all "Many to One" and not ambiguous.
 
Would you please help me identify what I am doing wrong?
Thanks a lot in advance,
Best,
Emilie
1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @emiliePowerBI -Here SUMX calculates row-by-row results in ACTYTDEUR, but the total doesn't correctly aggregate these individual conversions.

FX Rate calculation with necessary filters into account

 

FX Rate =
CALCULATE (
AVERAGE('FX Table'[FX Rate]),
FILTER(
'FX Table',
'FX Table'[Date] <= MAX(Dates[Date]) &&
'FX Table'[Date] >= STARTOFMONTH(Dates[Date]) &&
'FX Table'[Scenario] = SELECTEDVALUE('ABC Master'[Scenario]) &&
'FX Table'[Country code] = SELECTEDVALUE('ABC Master'[Country code]) &&
'FX Table'[Brand] = SELECTEDVALUE('ABC Master'[Brands])
)
)

 

Use a measure for the row-level conversion, making sure it respects the filter context

Converted Cost Row-Level =
DIVIDE([ACTYTD], [FX Rate])

 

we want to sum up each row’s conversion without directly summing the results of [Converted Cost Row-Level] to avoid incorrect totals

 

ACTYTDEUR =
IF(
HASONEVALUE('ABC Master'[Country code]) &&
HASONEVALUE('ABC Master'[Brands]) &&
HASONEVALUE('Dates'[Month]) &&
HASONEVALUE('Dates'[Year]),
-- Row-level calculation
[Converted Cost Row-Level],
-- Total calculation
CALCULATE(
SUMX(
'ABC Master',
[ACTYTD] / [FX Rate]
)
)
)

 

check and apply the above logic and let me know if any





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

3 REPLIES 3
emiliePowerBI
New Member

Thanks a lot for your quick answer!

shafiz_p
Resident Rockstar
Resident Rockstar

Hi @emiliePowerBI  

Your DAX measure test works well at the row level but not at the total level. This is a common issue when dealing with measures that involve division or other operations that don’t aggregate linearly.

One approach to solve this issue is to use SUMX to iterate over each row and then sum the results. This ensures that the calculation is done at the row level before summing up.

Try revising your test measure(For bridge table meaning evaluating against country code from bridge):
Test = SUMX('Bridge', [ACTYTD] / [FX Rate])

Ensure that the relationships between your tables are correctly set up.

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

 

rajendraongole1
Super User
Super User

Hi @emiliePowerBI -Here SUMX calculates row-by-row results in ACTYTDEUR, but the total doesn't correctly aggregate these individual conversions.

FX Rate calculation with necessary filters into account

 

FX Rate =
CALCULATE (
AVERAGE('FX Table'[FX Rate]),
FILTER(
'FX Table',
'FX Table'[Date] <= MAX(Dates[Date]) &&
'FX Table'[Date] >= STARTOFMONTH(Dates[Date]) &&
'FX Table'[Scenario] = SELECTEDVALUE('ABC Master'[Scenario]) &&
'FX Table'[Country code] = SELECTEDVALUE('ABC Master'[Country code]) &&
'FX Table'[Brand] = SELECTEDVALUE('ABC Master'[Brands])
)
)

 

Use a measure for the row-level conversion, making sure it respects the filter context

Converted Cost Row-Level =
DIVIDE([ACTYTD], [FX Rate])

 

we want to sum up each row’s conversion without directly summing the results of [Converted Cost Row-Level] to avoid incorrect totals

 

ACTYTDEUR =
IF(
HASONEVALUE('ABC Master'[Country code]) &&
HASONEVALUE('ABC Master'[Brands]) &&
HASONEVALUE('Dates'[Month]) &&
HASONEVALUE('Dates'[Year]),
-- Row-level calculation
[Converted Cost Row-Level],
-- Total calculation
CALCULATE(
SUMX(
'ABC Master',
[ACTYTD] / [FX Rate]
)
)
)

 

check and apply the above logic and let me know if any





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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