Forum Discussion

HamidBee's avatar
HamidBee
Icon for Power Participant rankPower Participant
4 years ago
Solved

DAX measure containing conditional statement does not show total values

I am working with the following data:

 

Total MinutesZones
456A
324B
785C
787D
343E
677A
234B
546C
898D
995E


I have created two measures:

 

ZoneParkingTime (minutes) = SUM('Parking Data'[Total Minutes])

and:

Petrol Price (£) = 

IF(
SELECTEDVALUE('Parking Data'[Zones])="A",([ZoneParkingTime (minutes)]*2/60),
IF(
SELECTEDVALUE('Parking Data'[Zones])="B",([ZoneParkingTime (minutes)]*6/60),
IF(
SELECTEDVALUE('Parking Data'[Zones])="C",([ZoneParkingTime (minutes)]*6/60),
IF(
SELECTEDVALUE('Parking Data'[Zones])="D",([ZoneParkingTime (minutes)]*3/60),
IF(
SELECTEDVALUE('Parking Data'[Zones])="E",([ZoneParkingTime (minutes)]*2/60)
)
)
)
)
)

The measure, Petrol Price (£) does not seem to give a total. I obtain the following results:

Does anyone have any idea as to why this may be happening?. I am attaching the file here if you would like to have a play around with it:

 

https://www.mediafire.com/file/rirkm73zvrnumxf/Conditional_Statement.pbix/file

 

Thank you,

  • Hi HamidBee ,

     

    Sorry deleted the first post as it wasn't giving totals. See below.

     

    Petrol Price (£) = SUMX(VALUES('Parking Data'[Zones]),IF(FIRSTNONBLANK('Parking Data'[Zones],1)="A",DIVIDE([ZoneParkingTime (minutes)]*2.8,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="B",DIVIDE([ZoneParkingTime (minutes)]*6.1,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="C",DIVIDE([ZoneParkingTime (minutes)]*6.1,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="D",DIVIDE([ZoneParkingTime (minutes)]*3.05,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="E",DIVIDE([ZoneParkingTime (minutes)]*2.8,60)
    ))))))

10 Replies

  • davehus's avatar
    davehus
    Icon for Memorable Member rankMemorable Member

    Hi HamidBee ,

     

    Sorry deleted the first post as it wasn't giving totals. See below.

     

    Petrol Price (£) = SUMX(VALUES('Parking Data'[Zones]),IF(FIRSTNONBLANK('Parking Data'[Zones],1)="A",DIVIDE([ZoneParkingTime (minutes)]*2.8,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="B",DIVIDE([ZoneParkingTime (minutes)]*6.1,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="C",DIVIDE([ZoneParkingTime (minutes)]*6.1,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="D",DIVIDE([ZoneParkingTime (minutes)]*3.05,60),
    IF(FIRSTNONBLANK('Parking Data'[Zones],1)="E",DIVIDE([ZoneParkingTime (minutes)]*2.8,60)
    ))))))
    • HamidBee's avatar
      HamidBee
      Icon for Power Participant rankPower Participant

      Nice. This DAX forumla works. I tried the one that you had deleted. So I was responding to that earlier. 

    • HamidBee's avatar
      HamidBee
      Icon for Power Participant rankPower Participant

      Thanks. I tried this but unfortunately it didn't work. 

       

      • AlexanderPrime's avatar
        AlexanderPrime
        Icon for Solution Supplier rankSolution Supplier

        Make it into a Column instead and drop SELECTEDVALUE from your code.

        Petrol Price £ =

        IF(
        ('Parking Data'[Zones])="A",([ZoneParkingTime (minutes)]*2/60),
        IF(
        ('Parking Data'[Zones])="B",([ZoneParkingTime (minutes)]*6/60),
        IF(
        ('Parking Data'[Zones])="C",([ZoneParkingTime (minutes)]*6/60),
        IF(
        ('Parking Data'[Zones])="D",([ZoneParkingTime (minutes)]*3/60),
        IF(
        ('Parking Data'[Zones])="E",([ZoneParkingTime (minutes)]*2/60)
        )
        )
        )
        )
        )




    • HamidBee's avatar
      HamidBee
      Icon for Power Participant rankPower Participant

      I'd kindly like to ask what the expression "1" in the equation refers to?