Reply
Chandrashekar
Resolver III
Resolver III

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
1 ACCEPTED SOLUTION

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:
ValtteriN_0-1641465953379.png


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!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
ValtteriN
Super User
Super User

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?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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

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:
ValtteriN_0-1641465953379.png


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!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello Team,

 

am trying to get result in below format.

Chandrashekar_0-1641466648596.png

 

Regards,

 

Chandrashekar B

Hi,

You can change the slicer in my example to a list and then make its alignment horizontal:

ValtteriN_0-1641467019974.png


Also to exclude today from the slicer you can modify the dax a bit:

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello Team,

 

Thanks for the solution.

 

Regards,

 

Chandrashekar B

Hello Team,

 

Can you please advise if still I can use if condition to acheive task.

 

My intention to explore more. Example below:

date period =
todayday=format(today(),"ddd"="Mon"

if(todayday,
ADDCOLUMNS(
DATESINPERIOD('date'[Date_rec],TODAY()-3,1,DAY),
"type",format(DATESINPERIOD('date'[Date_rec],TODAY()-3,1,DAY),"dd-mmm")
)
)

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)