Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have this variable:
So the question now.....can I make it so, that in the VAR rank_qty I swap the fixed text "'Backorder Details'[Origin])" with the variable outcome of measure Test?
I cannot put in the measure directly and I can also not use the dax code of measure Test directly in the VAR rank_qty (as I have it now)
Would there be a way to make this work?
Solved! Go to Solution.
Well I think I pulled it off with this code 😁:
But does anybody know how I can alter the code so it does not als rank the totals??
*EDIT: I found out! 😁
Did it in declaring the VARs :
Rank Measure =
VAR selected = SELECTEDVALUE(prmMeasure[Measure2])
VAR selected2 = SELECTEDVALUE(prmBreakdown[Breakdown])
VAR rank_org_qty = IF( HASONEVALUE('Backorder Details'[Origin]),RANKX(ALLSELECTED('Backorder Details'[Origin]),[BO Qty],,DESC))
VAR rank_org_usd = IF( HASONEVALUE('Backorder Details'[Origin]),RANKX(ALLSELECTED('Backorder Details'[Origin]),[USD Amt],,DESC))
VAR rank_pom_qty = IF( HASONEVALUE('Backorder Details'[POM]),RANKX(ALLSELECTED('Backorder Details'[POM]),[BO Qty],,DESC))
VAR rank_pom_usd = IF( HASONEVALUE('Backorder Details'[POM]),RANKX(ALLSELECTED('Backorder Details'[POM]),[USD Amt],,DESC))
VAR rank_pf_qty = IF( HASONEVALUE('Backorder Details'[PF Name]),RANKX(ALLSELECTED('Backorder Details'[PF Name]),[BO Qty],,DESC))
VAR rank_pf_usd = IF( HASONEVALUE('Backorder Details'[PF Name]),RANKX(ALLSELECTED('Backorder Details'[PF Name]),[USD Amt],,DESC))
RETURN
SWITCH(TRUE(),
selected = "BO Qty" && selected2 = "Origin", rank_org_qty,
selected = "USD Amt" && selected2 = "Origin", rank_org_usd,
selected = "BO Qty" && selected2 = "POM", rank_pom_qty,
selected = "USD Amt" && selected2 = "POM", rank_pom_usd,
selected = "BO Qty" && selected2 = "Prod.Fam. Name", rank_pf_qty,
selected = "USD Amt" && selected2 = "Prod.Fam. Name", rank_pf_usd
)
Thanks to @OwenAuger for putting me on the right track!
Well I think I pulled it off with this code 😁:
But does anybody know how I can alter the code so it does not als rank the totals??
*EDIT: I found out! 😁
Did it in declaring the VARs :
Rank Measure =
VAR selected = SELECTEDVALUE(prmMeasure[Measure2])
VAR selected2 = SELECTEDVALUE(prmBreakdown[Breakdown])
VAR rank_org_qty = IF( HASONEVALUE('Backorder Details'[Origin]),RANKX(ALLSELECTED('Backorder Details'[Origin]),[BO Qty],,DESC))
VAR rank_org_usd = IF( HASONEVALUE('Backorder Details'[Origin]),RANKX(ALLSELECTED('Backorder Details'[Origin]),[USD Amt],,DESC))
VAR rank_pom_qty = IF( HASONEVALUE('Backorder Details'[POM]),RANKX(ALLSELECTED('Backorder Details'[POM]),[BO Qty],,DESC))
VAR rank_pom_usd = IF( HASONEVALUE('Backorder Details'[POM]),RANKX(ALLSELECTED('Backorder Details'[POM]),[USD Amt],,DESC))
VAR rank_pf_qty = IF( HASONEVALUE('Backorder Details'[PF Name]),RANKX(ALLSELECTED('Backorder Details'[PF Name]),[BO Qty],,DESC))
VAR rank_pf_usd = IF( HASONEVALUE('Backorder Details'[PF Name]),RANKX(ALLSELECTED('Backorder Details'[PF Name]),[USD Amt],,DESC))
RETURN
SWITCH(TRUE(),
selected = "BO Qty" && selected2 = "Origin", rank_org_qty,
selected = "USD Amt" && selected2 = "Origin", rank_org_usd,
selected = "BO Qty" && selected2 = "POM", rank_pom_qty,
selected = "USD Amt" && selected2 = "POM", rank_pom_usd,
selected = "BO Qty" && selected2 = "Prod.Fam. Name", rank_pf_qty,
selected = "USD Amt" && selected2 = "Prod.Fam. Name", rank_pf_usd
)
Thanks to @OwenAuger for putting me on the right track!
Hi @rpinxt
I believe the only way to get this to work is to use the SWITCH function (or IF) to select the appropriate rank calculation based on the field parameter selection.
This would mean enumerating all possible selections for the field parameter within the arguments of the SWITCH function.
It would look something like this:
VAR breakdown_selection =
SELECTEDVALUE ( prmBreakdown[prmBreakdown Fields] )
VAR rank_qty =
SWITCH (
breakdown_selection,
"'Backorder Details'[Origin]",
RANKX( ALLSELECTED ( 'Backorder Details'[Origin] ), [BO Qty], , DESC ),
"'Backorder Details'[Other Column 1]",
RANKX( ALLSELECTED ( 'Backorder Details'[Other Column 1] ), [BO Qty], , DESC ),
"'Backorder Details'[Other Column 2]",
RANKX( ALLSELECTED ( 'Backorder Details'[Other Column 2] ), [BO Qty], , DESC )
)
and so on.
This code would need to be updated if the set of columns available for selection within this field parameter changed.
There's no way to swap out the text within a DAX expression to change the column reference unfortunately (a bit like how INDIRECT might be used in Excel).
Regards,
Owen
Thanks @OwenAuger .
And indeed INDIRECT of Excel would be somewhat the equivalent in Power BI what I was looking for.
Too bad something cannot be done (yet) in Power BI.
Specially with the new feature of Field Parameters this would be very welcome.
I made these VARs I mentioned already to Rank the outcome correctly when either Quantities or USD where chose (also a Field Parameter).
However they where fixed on 1 breakdown and for now we have 3.
So I guess my Switch would be then 6?
This is my working code now:
User | Count |
---|---|
117 | |
73 | |
58 | |
49 | |
48 |
User | Count |
---|---|
171 | |
122 | |
60 | |
59 | |
56 |