Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi, I am trying to make a report in PowerPivot where I dynamically select a reporting currency, and with a variable measure this will multiply my amount in SEK to any currency that I select in the slicer.
I have multiple currencies in my fact table (see tables below) and have converted those already to one global SEK amount which you can see in the "SEK amount" column. So the only thing left is to convert this SEK amount based on the currency I select in a slicer.
The Facts table is already linked with the exchange rate table through the "Currency Key".
However to make this work I created an extra table with all the reported currencies which is not linked to any table so that I can create the following measure:
Selected_Currency_reported:
=if(HASONEVALUE('Dim Currencies'[Currency]);VALUES('Dim Currencies'[Currency]);BLANK())
And then for the conversion measure below:
When I select GBP it is returning "test" which it should be as I did not yet include that currency to be selected.
However, I am getting blank values when multiplying my SEK amount with the looked-upvalue (or at least I think it selects a rate) exchange rate from the table. When I try to divide by the lookupvalue it gives a "NUM"-error.
The measure itself is working without any initial error, but somehow it is only returning me blanks when I select a relevant currency. Can anyone see what I'm doing wrong here?
=VAR selection = [Selected_Currency_reported]
return
switch(true();
selection = "CHF";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[currency key date];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "CZK"; SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[currency key date];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "EUR";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[currency key date];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "HUF";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[currency key date];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));BLANK())
I have the following Exchange rate table:
Exch rate table
Facts table
Currency table (not linked)
@Anonymous your formula looks ok not sure what is missig, why not replace following to var
selection = "CHF";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];
'Dim Exchange rates'[Datekey];'Fact PL Data'[currency key date];'Dim Exchange rates'[Currency];selction));
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Could you explain what you are trying to do with the var function now?
I managed to get it to work. I used lookupvalue on the wrong column which was not in the same format.
However => Is there an easier or prettier way to make this formula variable? Cause now if I would have a new currency in my selection, I would have to manually update my formula here:
=VAR selection = [Selected_Currency_reported]
return
switch(true();
selection = "CHF";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[Datekey currency];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "CZK"; SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[Datekey currency];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "EUR";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[Datekey currency];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "GBP";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[Datekey currency];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));
selection = "HUF";SUMX('Fact PL Data';'Fact PL Data'[SEK amount]*LOOKUPVALUE('Dim Exchange rates'[Exch. Rate];'Dim Exchange rates'[Datekey];'Fact PL Data'[Datekey currency];'Dim Exchange rates'[Currency];[Selected_Currency_reported]));"Incorrect values")
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |