Forum Discussion

ellynneu's avatar
ellynneu
New Member
2 years ago
Solved

DAX Measure with Parameter

Hello,
I am struggling to write the correct DAX measure, most likely due to the measures referencing a paramater.

Here is my current data:
I have Shift (static within table 'Shift Hours') and a user selected parameter for each shift called 'Active' that toggles between 0 (inactive) and 1 (active). 

 



My measure for the Active Field (which references the parameters) is as follows:

Active_Param =
Var Shifty = max('Shift-Hours'[Shift])
RETURN
if(or(and(Shifty="1",[577_1Active Value]=1),or(
and(Shifty="2",[577_2Active Value]=1),or(
and(Shifty="3",[577_3Active Value]=1),
and(Shifty="5",[577_5Active Value]=1))))),1,0)

 

I need a measure to return 360, 480 or 0 for the following scenerios:

If shift = 1 and Active = 1 && shift = 2 and Active = 1 && Shift = 3 and Active = 1 then 360
if shift = 1 and Active = 1 && shift = 2 and Active = 1 && Shift = 5 and Active = 1 then 480
else 0

Current scenerio:
I only have Shift 1, 2, and 3 Selected as ACTIVE so I should have a value of 360.

Here is my current measure that does not work.
while it "works" at the row context level in a table, it does not return a singular value of 360

Value =

VAR Shifty = max('Shift-Hours'[Shift])
RETURN
if([Active_Param]=1,
if(
    Shifty="1"||Shifty="2"||Shifty="3",360,0),0)


I have tried so many different variations. I have tried using Sumx and still no luck.
Value:

Var Shifty = max('Shift-Hours'[Shift])
Var Activey = [Active_Param]
Var rowVal = if(Activey=1,if( Shifty="1"||Shifty="2"||Shifty="3",360,0),0)
return

SUMX(
    'Shift-Hours',
   rowVal)



I am probably over thinking it. Please help. 



It would be very easy in excel like so:

 



  • I figured it out! I had to call the parameter values as the variables.

    I used the following measure:

    Var sone = SELECTEDVALUE('577_1Active'[577_1Active])
    Var stwo = SELECTEDVALUE('577_2Active'[577_2Active])
    Var sthree = SELECTEDVALUE('577_3Active'[577_3Active])
    Var sfive = SELECTEDVALUE('577_5Active'[577_5Active])
    return
    if(sone=1&&stwo=1&&sthree=1&&sfive=1,360,0)



1 Reply

  • I figured it out! I had to call the parameter values as the variables.

    I used the following measure:

    Var sone = SELECTEDVALUE('577_1Active'[577_1Active])
    Var stwo = SELECTEDVALUE('577_2Active'[577_2Active])
    Var sthree = SELECTEDVALUE('577_3Active'[577_3Active])
    Var sfive = SELECTEDVALUE('577_5Active'[577_5Active])
    return
    if(sone=1&&stwo=1&&sthree=1&&sfive=1,360,0)