Forum Discussion

Chandrashekar's avatar
Chandrashekar
Resolver III
4 years ago
Solved

Addcolumns with Condtions

Hello Team,

 

am new to Power Bi. Can you guide how to addcolumns when condition met(Example below)

In below example if day is Thursday then I need to addcolumns.
 
date period =
var todayday=format(today(),"ddd")="Thu"
return
var columnadd=
ADDCOLUMNS(
     DATESINPERIOD('date'[Date_rec],TODAY()-3,1,DAY),
     "Type", "Day3"
)
return
 
Regards,
 
Chandrashekar B
  • ValtteriN's avatar
    ValtteriN
    4 years ago

    I see, in cases like these you can create a filter measure and use that to filter your slicer.

    Example: 

    Last 3 days slicer = IF(max('Calendar example'[Date])>=TODAY()-3 && max('Calendar example'[Date])<=TODAY(),1,0)

    End result in slicer:


    I hope this helps to solve your issue and if it does consider accepting this as a solution and gicing the post a thumbs up!

7 Replies

  • ValtteriN's avatar
    ValtteriN
    Community Champion

    Hi,

    Could you specify a bit more what you are trying to accomplish? ADDCOLUMNS creates a new table which has columns from your original table and then new columns e.g. SUMX columns. Where and why do you want to add this data in question?

    • Chandrashekar's avatar
      Chandrashekar
      Resolver III

      Hello,

       

      am trying to add last 3 days in Slicer. If it is Monday slicer should display last 3 days for ex:

      Day=today(10-Jan-2022 Monday) then slicer should display below dates

      1. 29-Dec-2021 Wed

      2. 30-Dec-2021 Thu

      3. 31-Dec-2021 Fri

       

      Regards,

       

      Chandrashekar B

      • ValtteriN's avatar
        ValtteriN
        Community Champion

        I see, in cases like these you can create a filter measure and use that to filter your slicer.

        Example: 

        Last 3 days slicer = IF(max('Calendar example'[Date])>=TODAY()-3 && max('Calendar example'[Date])<=TODAY(),1,0)

        End result in slicer:


        I hope this helps to solve your issue and if it does consider accepting this as a solution and gicing the post a thumbs up!