Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
user_34
Frequent Visitor

Creating a table which has dynamic header and data

Hi all 
I am creating a new table in which I am creating a date picker using this DAX
Calendar =
VAR Days = CALENDAR ( DATE ( 2024, 1, 1 ), DATE ( 2024, 12, 31 ) )
RETURN ADDCOLUMNS (
Days,
"Formatted Date", FORMAT([Date], "yyyy-mm-dd"),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month", FORMAT ( [Date], "mmmm" ),
"Year Month Number", YEAR ( [Date] ) * 12 + MONTH ( [Date] ) - 1,
"Year Month", FORMAT ( [Date], "mmm yy" ),
"Week Number", WEEKNUM ( [Date] ),
"Week Number and Year", "W" & WEEKNUM ( [Date] ) & " " & YEAR ( [Date] ),
"WeekYearNumber", YEAR ( [Date] ) & 100 + WEEKNUM ( [Date] ),
"Is Working Day", NOT WEEKDAY([Date]) IN {1,7}
)
Now I have data 

CategoryFileStart TimeTarget TimeReceived TimeFinal timeDate
As32983:00 AM8:00 AM3:00 AMMet08-04-2024
As32993:00 AM8:00 AM4:00 AMMet07-04-2024
As33003:00 AM8:00 AM5:00 AMMet06-04-2024
As33013:00 AM8:00 AM6:00 AMMet08-04-2024
As33023:00 AM8:00 AM7:00 AMMet07-04-2024
As33033:00 AM8:00 AM8:00 AMMet06-04-2024
As33043:00 AM8:00 AM9:00 AMNot Met08-04-2024
Bs33054:00 AM8:00 AM10:00 AMNot Met07-04-2024
Bs33065:00 AM8:00 AM11:00 AMNot Met06-04-2024
Bs33076:00 AM8:00 AM12:00 PMNot Met08-04-2024
Bs33087:00 AM8:00 AM1:00 PMNot Met07-04-2024
Bs33098:00 AM8:00 AM2:00 PMNot Met06-04-2024
Bs33109:00 AM9:00 AM  08-04-2024


Now I want create a table in which category name and today date,yesterday date and day before yesterday date as a header  in which target should show as values where I want to apply conditional formatting like

1. for 8 April for the category a if their final time is between target time and start time it should show green 

2. if final time =null but system time > Target time  show red
3. if final time =null but system time < Target time  show yellow
Attaching the excel file 
https://docs.google.com/spreadsheets/d/1DQd8Xj1mJzYnZeTWXmgNRJIOwCLaz10lBBKsDQK91q4/edit?usp=sharing

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @user_34 ,

Thanks for the reply from @amitchandak , please allow me to provide another insight: 

 

Here are the steps you can follow:

1. Create measure.

color =
var _today=TODAY()
return
SWITCH(
    TRUE(),
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])>=MAX('Table'[Start Time])&&MAX('Table'[Final time])<=MAX('Table'[Target Time]),"green",
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])=BLANK()&&MAX('Table'[Start Time])>MAX('Table'[Target Time]),"red",
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])=BLANK()&&MAX('Table'[Start Time])<MAX('Table'[Target Time]),"yellow")

2. Select filed – Conditional formatting – Background color.

vyangliumsft_0-1712654043711.png

 

vyangliumsft_1-1712654043713.png

3. Result:

vyangliumsft_2-1712654099193.png

 

Best Regards,

Liu Yang

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

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @user_34 ,

Thanks for the reply from @amitchandak , please allow me to provide another insight: 

 

Here are the steps you can follow:

1. Create measure.

color =
var _today=TODAY()
return
SWITCH(
    TRUE(),
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])>=MAX('Table'[Start Time])&&MAX('Table'[Final time])<=MAX('Table'[Target Time]),"green",
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])=BLANK()&&MAX('Table'[Start Time])>MAX('Table'[Target Time]),"red",
    MAX('Table'[Date])=_today&&MAX('Table'[Final time])=BLANK()&&MAX('Table'[Start Time])<MAX('Table'[Target Time]),"yellow")

2. Select filed – Conditional formatting – Background color.

vyangliumsft_0-1712654043711.png

 

vyangliumsft_1-1712654043713.png

3. Result:

vyangliumsft_2-1712654099193.png

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@user_34 , You can create a measure and use that in conditional formatting using field value option

 

example measures

 

 

Color = Switch( True() ,
Max(Table[Status]) < 200 ,
Switch(true(),
[ERB] = .25 , "Orange" ,
"Red "
) ,
Max(Table[Status]) < 500 ,
Switch(true(),
[ERB] = .25 , "Orange" ,
"Red "
) ,
Switch(true(),
[ERB] = .25 , "Orange" ,
"Red "
)
)

Color Date =
var _min =minx(allselected(Date,Date[Year])
return
Switch( true(),
FIRSTNONBLANK('Date'[Year],year(TODAY()))-_min =0 ,"lightgreen",
FIRSTNONBLANK('Date'[Year],year(TODAY()))-_min =0 ,"blue",
"red")

 

How to do conditional formatting by measure and apply it on pie?
https://www.youtube.com/watch?v=RqBb5eBf_I4&list=PLPaNVDMhUXGYo50Ajmr4SgSV9HIQLxc8L
https://community.powerbi.com/t5/Community-Blog/Power-BI-Conditional-formatting-the-Pie-Visual/ba-p/...
https://amitchandak.medium.com/power-bi-where-is-the-conditional-formatting-option-in-new-format-pan...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.