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.
Hello,
Please help with dynamic format.
I need three conditions:
1. each country has its own currency (done)
2. if 2 specific countries are selected, display data in one currency (need help)
3. for all other cases - there is no formatting with currency, just numbers (done)
VAR _eu1 = FILTER ( 'Hierarchy', 'Hierarchy'[Country] = "Country 1" )
VAR _eu2 = FILTER ( 'Hierarchy', 'Hierarchy'[Country] = "Country 2" )
VAR _eu = _eu1 && _eu2
--
VAR _car1 = FILTER ( 'Hierarchy', 'Hierarchy'[Country] = "Country 3" )
VAR _car2 = FILTER ( 'Hierarchy', 'Hierarchy'[Country] = "Country 4" )
VAR _car = _car1 && _car2
--
RETURN
SWITCH (
TRUE (),
SELECTEDVALUE ( 'Hierarchy'[Country] ) = "Country 1", "A #,0.00",
SELECTEDVALUE ( 'Hierarchy'[Country] ) = "Country 2", "B #,0.00",
SELECTEDVALUE ( 'Hierarchy'[Country] ) = "Country 3", "C #,0.00",
SELECTEDVALUE ( 'Hierarchy'[Country] ) = "Country 4", "D #,0.00",
SELECTEDVALUE ( 'Hierarchy'[Country] ) = "Country 5", "E #,0.00",
_eu1 && _eu2, "F #,0.00",
_car1 && _car2, "G #,0.00",
"#,0.00"
)
Solved! Go to Solution.
hi @DmitryAD7
These two sound more like a hypothetical scenario. You don't want to hardcode currency/country/formattting. It should be dynamic. Please check below solution if it works as per your requirement.
If only two countries are selected Country 1 and Country 2 - currency format is "F #,#".
If only two countries are selected Country 4 and Country 5 - currency format is "G #,#".
Created duplicate table to yours and added currency symbol to table itself.
Then created this measure.
Hello @talespin and @Sahir_Maharaj
Sample file. What I expect:
If all countries are selected in a slicer or none are selected, the default currency formatting is "#,#".
If one country is selected, the formatting for each country is different: “A #,#”, “B #,#”, “C #,#”, etc.
If only two countries are selected Country 1 and Country 2 - currency format is "F #,#".
If only two countries are selected Country 4 and Country 5 - currency format is "G #,#".
@Sahir_Maharajthanks, but In your solution, If all countries are selected in the slicer or none are selected, the default currency formatting is "F #,#", not "#,#".
hi @DmitryAD7
These two sound more like a hypothetical scenario. You don't want to hardcode currency/country/formattting. It should be dynamic. Please check below solution if it works as per your requirement.
If only two countries are selected Country 1 and Country 2 - currency format is "F #,#".
If only two countries are selected Country 4 and Country 5 - currency format is "G #,#".
Created duplicate table to yours and added currency symbol to table itself.
Then created this measure.
Hello @talespin . No more help needed in that case, tahnks a lot for your help. I have converted your measure to a dynamic format string.
Thanks!
Good day @talespin .
Thank you, the result is correct now).
But I don't want to add this condition to my main measure, (not to complicate it). I would like to use the dynamic data format option:
could you please help to transform you measure for this option?
Hello @DmitryAD7,
Can you please try the following:
Dynamic Currency Format =
VAR _selectedCountries = ALLSELECTED('Hierarchy'[Country])
VAR _isEuSelected =
CONTAINS(_selectedCountries, 'Hierarchy'[Country], "Country 1") &&
CONTAINS(_selectedCountries, 'Hierarchy'[Country], "Country 2")
VAR _isCarSelected =
CONTAINS(_selectedCountries, 'Hierarchy'[Country], "Country 3") &&
CONTAINS(_selectedCountries, 'Hierarchy'[Country], "Country 4")
VAR _selectedCount = COUNTROWS(_selectedCountries)
RETURN
SWITCH (
TRUE(),
_selectedCount = 1 && SELECTEDVALUE('Hierarchy'[Country]) = "Country 1", "A #,0.00",
_selectedCount = 1 && SELECTEDVALUE('Hierarchy'[Country]) = "Country 2", "B #,0.00",
_selectedCount = 1 && SELECTEDVALUE('Hierarchy'[Country]) = "Country 3", "C #,0.00",
_selectedCount = 1 && SELECTEDVALUE('Hierarchy'[Country]) = "Country 4", "D #,0.00",
_selectedCount = 1 && SELECTEDVALUE('Hierarchy'[Country]) = "Country 5", "E #,0.00",
_isEuSelected, "F #,0.00", // For combined selection of Country 1 and Country 2
_isCarSelected, "G #,0.00", // For combined selection of Country 3 and Country 4
"#,0.00" // Default formatting
)
hi @DmitryAD7
I believe you are writing too many lines of code to format. If you can explain what you have and what you expect, maybe we can propose a better solution.
- Sample data from table.
- What output you expect.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
7 |