DAX measure to get rate from dislocated table

RicoS

Board Regular
Joined
May 1, 2019
Messages
62
Hi,

I am struggling to return a result with a Dax formula. I have a Fact table that has some data

Fact Table
DateAccountCurrTrans AmtGBP EquivUSD Equiv
01/04/1812345EUR10,0009,00014,000
01/05/1812445USD15,00010,00015,000
01/10/1812445GBP1,0001,0001,425

<tbody>
</tbody>

I have a dislocated (disCurr) table (no relationship, I just use it for a slicer) that allows the user to select GBP or USD as the report currency and a measure called report amount which returns either GBP or USD equivalent based on that selection. This works without issue. This measure returns a cumulative values based on a date table, again without issue:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]ReportAmount:=IF(MAX(disCurr[Report Currencies])="GBP",CALCULATE(SUM([GBP Equiv]),FILTER(ALL(dDates),dDates[Date]<=MAX(dDates[Date]))),IF(MAX(disCurr[Report Currencies])="USD",CALCULATE(SUM([USD Equiv]),FILTER(ALL(dDates),dDates[Date]<=MAX(dDates[Date]))),0))[/FONT]

However, my transaction table's USD Equivalent is based on the date entered into the table, so I have a rates table that I want to use to get the USD/GBP equiv at the maximum date selected in the date slicer, which I can then use to multiply by SUM([Trans Amt]) and get the value of the transaction at today's rate.

I have a dRates table:
DateCurr FromCurr ToRate
01/05/18EURGBP0.8
01/05/18EURUSD1.2
01/05/18GBPUSD1.4
01/10/18EURGBP0.9
01/10/18EURUSD1.3
01/10/18USDGBP1.54

<tbody>
</tbody>

I have a unique currencies (uCurr) table with a relationship from fact table and to the rates table

fTable[Curr]->uCurr[Curr]
uCurr[Curr]->dRates[Curr From]

In my pivot table I output [Account], uCurr[Curr], [Report amount] and I was hoping to retrieve the Rate with a simple calculate measure:

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]DateRate:=IF([ReportAmount]=0,BLANK(),CALCULATE(SUM(dRates[Rate]),FILTER(dRates,dRates[Curr From]=MAX(uCurr[Curr])&&dRates[Curr To]=MAX(disCurr[Curr])&&dRates[Date]=MAX(dDate[Date])))[/FONT]

However this returns nothing (it does not return an error, just blank and the report amounts are visibly not blank in the row)

I split the Measure into 3 separate measures and populated my pivot table with them to check to see if they returned the correct answers:

Code:
LineCurr:=IF([ReportAmount]=0,BLANK(),IF(HASONEFILTER(uCurr[Curr]),MAX(uCurr[Curr]),"N"))

Code:
RateDate:=[LEFT][COLOR=#222222][FONT=Verdana]IF([ReportAmount]=0,BLANK(),MAX(dDate[Date]))

Code:
ReportCurr:=[LEFT][COLOR=#222222][FONT=Verdana]IF([ReportAmount]=0,BLANK(),MAX(disCurr[Curr]))

All the above return the expected values (for example, LineCurr as per each line in the fact table, RateDate as per the date slicer and ReportCurr as per the Report currency selected in its slicer)

When I combine into one measure, I just cannot seem to get the Rate returned. I even substituted my above measure into my original formula, without success again:

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Code:
DateRate:=IF([ReportAmount]=0,BLANK(),CALCULATE(SUM(dRates[Rate]),FILTER(dRates,dRates[Curr From]=[LineCurr]&&dRates[Curr To]=[ReportCurr]&&dRates[Date]=[RateDate])))

At this point, I'm a little stuck! Any help would be much appreciated. DAX sometimes has that ability to make something that seems very simply be very hard (but with great rewards when correct)!

[/FONT]Cheers,
Rico
<strike>
</strike>
[/FONT][/COLOR][/LEFT]<strike>
</strike>
[/FONT][/COLOR][/LEFT]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top