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.
Let’s say I’ve below areas as a table value.
Area |
USA |
UK |
AUS |
CAN |
I’ve created a measure for selected item from the Area table. (It’s always one selected in slicer).
SelectedArea = SelectedValue(Area)
Now, suppose my fact table has different sales columns for each area like below.
Sales |
Sales_USA |
Sales_UK |
Sales_AUS |
Sales_CAN |
USA Sales := Sum(Sales_USA)
So, my question is here instead of creating Sales for each area, can we automate this something like below?
Sales := Sum(Sales_[SelectedArea])
Based on the selection in Area column the measure should update.
I can create measure of each area and use switch statement but the problem is I’ve more than 50 different measures.
Any help would be appreciated.
Solved! Go to Solution.
Hi @Anonymous ,
Sorry for our delay in response, but it does not support to calculate dynamic formula/field in measure, but we can use "unpivot" in power query editor to meet your requirement:
If you do not want to change the construction of data, we can use switch to calculate for each area:
Sales =
SUMX (
DISTINCT ( Country[Country] ),
SWITCH (
[Country],
"USA", SUM ( Sales[Sales_USA] ),
"BRA", SUM ( Sales[Sales_BRA] ),
"CAN", SUM ( Sales[Sales_CAN] ),
"JPN", SUM ( Sales[Sales_JPN] )
)
)
By the way, PBIX file as attached.
Best regards,
Hi,
Your data is not well arranged. You should unpivot your data to have all Countries appear in 1 column only and in another column you have have the sales figures.
Hi @Ashish_Mathur , I took the the above data just an example to explain the scenario but in reality the data and the usecase is different and we can't change the data foramt for various reasons.
I've created a measure as below.
Hi @Anonymous ,
Sorry for our delay in response, but it does not support to calculate dynamic formula/field in measure, but we can use "unpivot" in power query editor to meet your requirement:
If you do not want to change the construction of data, we can use switch to calculate for each area:
Sales =
SUMX (
DISTINCT ( Country[Country] ),
SWITCH (
[Country],
"USA", SUM ( Sales[Sales_USA] ),
"BRA", SUM ( Sales[Sales_BRA] ),
"CAN", SUM ( Sales[Sales_CAN] ),
"JPN", SUM ( Sales[Sales_JPN] )
)
)
By the way, PBIX file as attached.
Best regards,
Hi @Anonymous ,
I create a pbix file with an example.
I hope this file helps you: Download PBIX
Ricardo
@camargos88 Thanks for your quick response. I know this is one way of doing it. But I wanted to completly avoid creating bunch of measures or If conditions. Essentially I want to create a single measure and dynamically update the column name based on the selections in area slicer.
SelectedValue = SelectedValue(area)
Current: Sum(Sales_USA) (for each area)
Expected: Sales := Sum(Sales_[SelectedValue])
Suppose If I selected USA, my sales measure should become Sum(Sales_USA) and If i select UK it should become Sum(Sales_UK). Simply I want to control [SelectedValue] based on selection in area slicer. So this way I can avoid creating so many measures or if conditions.
Is it possible to use varible or measure in the column names?
I understand but the probelm is i'm using direct query with 250millions records. writing more if conditions severely affects the performance. I'm looking for more elegant solution.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
115 | |
100 | |
88 | |
68 | |
61 |
User | Count |
---|---|
150 | |
120 | |
100 | |
87 | |
68 |