Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
I'm just curious if something similar to the functionality of lists/dictionaries in python exists in Power BI.
Quite often I want to do things like 'If the selected area is in X list', but i don't think this kind of thing is replicated in PBI anywhere? What i typically do instead is create some kind of lookup table that has a column indicating if the area is in a group or not.
A quick example, I wanted to figure out how to specify different aggregation types according to slicer value (e.g. tell a measure to sum values if it makes sense to sum them, but if the value selected requires an average instead of a sum, recognse that and do that instead. In python you might do this in a dictionary, something like the below to tell a formula how to handle different values:
Aggregation_Type_to_Use = {
"Number of houses" : "sum",
"House Price" : "average"}
Is there any way to do this in a simlar way or would you use lookup tables instead? In the example above, i'm guessing i'd need to add a column indicating the correct aggregation type and reference that in a formula? Something like the below quick example?
Answer =
var agg_type_column = max('FactTbl['Aggregation type to use'])
var sum_measure = sum('FactTbl'[value])
var avg_measure = average('FactTbl'[value])
return if(agg_type_column = 'sum', sum_measure, average_measure)
Thanks
Solved! Go to Solution.
Hi @GlassShark1
According to your quick example at the end, it is possible. But the 'Aggregation type to use' column should be from an individual table rather than the fact table. That table should be disconnected from the fact table. Then use a measure like
Answer =
VAR agg_type_column = MAX ( 'Types'[Aggregation type to use] )
RETURN
SWITCH ( agg_type_column, "sum", [sum_measure], "average", [average_measure] )
Here is a blog which has a detailed explanation about this solution: Change the Column or Measure Value in a Power BI Visual by Selection of the Slicer: Parameter Table ...
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi @GlassShark1
According to your quick example at the end, it is possible. But the 'Aggregation type to use' column should be from an individual table rather than the fact table. That table should be disconnected from the fact table. Then use a measure like
Answer =
VAR agg_type_column = MAX ( 'Types'[Aggregation type to use] )
RETURN
SWITCH ( agg_type_column, "sum", [sum_measure], "average", [average_measure] )
Here is a blog which has a detailed explanation about this solution: Change the Column or Measure Value in a Power BI Visual by Selection of the Slicer: Parameter Table ...
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Just like the fact that there doesn't now exist a native func of SWITCH/CASE in python, you can't expect all syntactic equivalents in another language. Just paste mock-up dataset and articulate what you expect.
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
91 | |
86 | |
76 | |
66 |
User | Count |
---|---|
149 | |
117 | |
111 | |
106 | |
95 |