Forum Discussion

Learner_SG's avatar
Learner_SG
Helper IV
4 years ago
Solved

Power BI DAX

Hi ,Could anyone help me this DAX. 

Date HoursUsageOccupancy
27-Feb 251
27-Feb 472
27-Feb 783
27-Feb331
27-Feb921
27-Feb542
27-Feb716
27-Feb365
27-Feb813
27-Feb1032
26-Feb1241
26-Feb1461
26-Feb614
26-Feb816
26-Feb1024
26-Feb142
26-Feb331
26-Feb1373

Based on this data, I need to write a DAX to select the 4 highest times for each day when the usage+occupancy is high.Could anyone help?

  • Hi Learner_SG ï¼Œ

    I got it. Here's my solution.

    1.Create a check measure.

    Check = IF(MAX('Sheet4'[Parsed_Date])=TODAY()-7,1)

    Put the measure in the visual filter and let the value is 1.

    2. Create a rank measure.

    Rank =
    RANKX (
        FILTER ( ALL ( 'Sheet4' ), 'Sheet4'[Parsed_Date] = TODAY () - 7 ),
        CALCULATE ( SUM ( 'Sheet4'[WC Water Consumption(mL)] ) ),
        ,
        DESC,
        DENSE
    )
    

    Put the measure in the visual filter and let the value <=4, get the correct result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

22 Replies

  • Hi Learner_SG ,

    do you mean display the 4 highest times in the last 7 days? If this is the case, here's my solution.

    1.Create a date table.

    Date = CALENDAR(DATE(2022,1,1),TODAY())

    2.Make relationship between the two tables, note the Parsed date should be Date type.

    3.Put the date column in a slicer, select Relative Date>Last 7 Days.

    4.In the visual filter, put WC Water Consumption in the box below "By value", and select Top 4.

    It will always get the top 4 values in the last 7 days.

     

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

     

     

    • Learner_SG's avatar
      Learner_SG
      Helper IV

      Hi v-yanjiang-msft , thanks for the detailed explanation and solution. In fact my requirement is that , I need to display in the table ,  previous 7th day data. that means, if i display the dashboard today(friday), it should show me the last friday's 4 highest time  when the usage+occupancy is high and it will change each day. Hope its clear now. Sorry,if my earlier phrasing of the sentence caused confusion.  Could you guide me on this?

      • v-yanjiang-msft's avatar
        v-yanjiang-msft
        Community Support

        Hi Learner_SG ï¼Œ

        I got it. Here's my solution.

        1.Create a check measure.

        Check = IF(MAX('Sheet4'[Parsed_Date])=TODAY()-7,1)

        Put the measure in the visual filter and let the value is 1.

        2. Create a rank measure.

        Rank =
        RANKX (
            FILTER ( ALL ( 'Sheet4' ), 'Sheet4'[Parsed_Date] = TODAY () - 7 ),
            CALCULATE ( SUM ( 'Sheet4'[WC Water Consumption(mL)] ) ),
            ,
            DESC,
            DENSE
        )
        

        Put the measure in the visual filter and let the value <=4, get the correct result.

        I attach my sample below for reference.

         

        Best Regards,
        Community Support Team _ kalyj

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Hi,

     

    Can you try below measure and use it as visual filter please?

     

    rank =

    RANKX
    (
    ALLEXCEPT('Table','Table'[Date]),
    [usage_occ],
    ,
    DESC,
    Skip
    )