Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi all,
I am trying, for the first time to use variables, but I have come a little unstuck and I know the below is not correct, but hopefully it will help to understand what I am doing.
I have a table that is just a list of Part Numbers with results under columns for each month, QTR and HY. I am looking to get the current QTR and then based on that and the Part Number that has been filtered, to select the appropriate number from the correct QTR column.
i.e.
Part Number QTR1 QTR2 QTR3 QTR4
1234567 100 200 300 400
So if current QTR is 1 and Part Number 1234567 has been selected on the filter then return column QTR1 and so on.
What I have so far is:
Solved! Go to Solution.
@Rich_Wyeth , Try using
DAX
M_CURRENTQTR_Value =
VAR vPart = SELECTEDVALUE('QTY SOLD DATA TABLE'[Part Number])
VAR vQTRCurrent = [M_CURRENTQTR]
VAR vTable = FILTER('QTY SOLD DATA TABLE', [Part Number] = vPart)
VAR vResult =
SWITCH(
TRUE(),
vQTRCurrent = 1, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR1]),
vQTRCurrent = 2, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR2]),
vQTRCurrent = 3, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR3]),
vQTRCurrent = 4, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR4]),
0
)
RETURN vResult
Proud to be a Super User! |
|
@Rich_Wyeth , Try using
DAX
M_CURRENTQTR_Value =
VAR vPart = SELECTEDVALUE('QTY SOLD DATA TABLE'[Part Number])
VAR vQTRCurrent = [M_CURRENTQTR]
VAR vTable = FILTER('QTY SOLD DATA TABLE', [Part Number] = vPart)
VAR vResult =
SWITCH(
TRUE(),
vQTRCurrent = 1, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR1]),
vQTRCurrent = 2, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR2]),
vQTRCurrent = 3, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR3]),
vQTRCurrent = 4, MAXX(vTable, 'QTY SOLD DATA TABLE'[QTR4]),
0
)
RETURN vResult
Proud to be a Super User! |
|
Thank you so much, works a treat. I can see where I was going wrong, all learning in progress.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 50 | |
| 44 | |
| 42 | |
| 19 | |
| 19 |
| User | Count |
|---|---|
| 70 | |
| 68 | |
| 33 | |
| 32 | |
| 32 |