Forum Discussion

Rich_Wyeth's avatar
Rich_Wyeth
Helper I
1 year ago
Solved

Using variables to return a result

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 hav...
  • bhanu_gautam's avatar
    1 year ago

    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