Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Date in Power BI

Hello All,

 

I am new to Power BI.

I have a report where I need to filter the data based on my slicer value.

 

Lets say if my slice value is Daily then I need to show only last 12 days data

and If my slice value is Weekly then I need to show only last 5 Weeks data.

 

Could any one please help, how to do this

8 Replies

  • Samarth_18's avatar
    Samarth_18
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous ,

     

    Please try below measure :-

    Measure =
    VAR selected_value =
        SELECTEDVALUE ( Slicer_Table[Slicer_value] )
    VAR last_12_day =
        IF (
            CALCULATE (
                MAX ( Dates[Date] ),
                FILTER ( Dates, Dates[Date] >= TODAY () - 12 && Dates[Date] <= TODAY () )
            ),
            1,
            0
        )
    VAR last_5_week =
        IF (
            CALCULATE (
                MAX ( Dates[Date] ),
                FILTER ( Dates, Dates[Date] >= TODAY () - 35 && Dates[Date] <= TODAY () )
            ),
            1,
            0
        )
    RETURN
        IF ( selected_value = "Daily", last_12_day, last_5_week )

     

    and use it as filter:-

     

    Refer below file for reference.

     

    Thanks,

    Samarth

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Samarth_18 ,

       

      Could you please let me know where I need put my slicer values here (Daily and Weekly )

      I dont see in the measure you created.

       

      Please correct me If I am wrong

       

      Measure =
      VAR selected_value =
          SELECTEDVALUE ( Slicer_Table[Slicer_value] )
      VAR last_12_day =
          IF (
              CALCULATE (
                  MAX ( Dates[Date] ),
                  FILTER ( Dates, Dates[Date] >= TODAY () - 12 && Dates[Date] <= TODAY () )
              ),
              1,
              0
          )
      VAR last_5_week =
          IF (
              CALCULATE (
                  MAX ( Dates[Date] ),
                  FILTER ( Dates, Dates[Date] >= TODAY () - 35 && Dates[Date] <= TODAY () )
              ),
              1,
              0
          )
      RETURN
          IF ( selected_value = "Daily", last_12_day, last_5_week )

       

       

      • Samarth_18's avatar
        Samarth_18
        Icon for Community Champion rankCommunity Champion

        Anonymous , Replace the below table with your slicer table which is having value like daily or weekly.

        Slicer_Table[Slicer_value]