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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
RENJITH_R_S
Resolver I
Resolver I

Week Calculaltion

Friends

 Please help on this to make a calculated columnTick.png

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @RENJITH_R_S 

Then you can change the code to this

Column = SWITCH(
    
        TRUE(),
        
        'Table'[Value] = "d", 1,  //Green
        
        'Table'[Value] = "a", 2,  //Grey

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 7, 3, //Blue

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) >= 7 && DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 14, 4, //Yellow

        5 //Red

    )

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

9 REPLIES 9
PhilipTreacy
Super User
Super User

Hi @RENJITH_R_S 

Then you can change the code to this

Column = SWITCH(
    
        TRUE(),
        
        'Table'[Value] = "d", 1,  //Green
        
        'Table'[Value] = "a", 2,  //Grey

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 7, 3, //Blue

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) >= 7 && DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 14, 4, //Yellow

        5 //Red

    )

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


@PhilipTreacy thank  you

amitchandak
Super User
Super User

@RENJITH_R_S , Create a new column like

 

Create a column like
Week Color = Switch( True(),
(Table[Value]) = "d", "Green",
(Table[Value]) = "2", "Grey",
[DateValue] >=today()+-1*WEEKDAY(today(),2)+1 && [DateValue] >= today()+ 7-1*WEEKDAY(today(),2) ,"blue" ,
[DateValue] >= today()+-1*WEEKDAY(today(),2)+1 -7 && [DateValue] >= today()+ 7-1*WEEKDAY(today(),2)-7 ,"yellow" ,
"red"
)

 

// for monday week WEEKDAY(today(),2)

//for Sunday Week WEEKDAY(today(),1)

Thanks @amitchandak for the response

@RENJITH_R_S , On correction. One I mentioned above is column.

For color measure use

 

Create a measure like
Week Color = Switch( True(),
max(Table[Value]) = "d", "Green",
max(Table[Value]) = "2", "grey",
max([DateValue]) >=today()+-1*WEEKDAY(today(),2)+1 && max([DateValue]) >= today()+ 7-1*WEEKDAY(today(),2) ,"blue" ,
max([DateValue]) >= today()+-1*WEEKDAY(today(),2)+1 -7 && max([DateValue]) >= today()+ 7-1*WEEKDAY(today(),2)-7 ,"yellow" ,
"red"
)

 

you can use 6 digit hexcode with #

example green = #00FF00

PhilipTreacy
Super User
Super User

Hi @RENJITH_R_S 

It's not entirely clear what you want, for example, what do you mean by this week?  Are you talking within the last 7 days, or the 7 days starting from last Sunday/Monday?

Also, not sure what the colour/number table is for.  Do you want the name of the colour as output or a number?

Try this

Column = SWITCH(
    
        TRUE(),
        
        'Table'[Value] = "d", "Green",
        
        'Table'[Value] = "a", "Grey",

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 7, "Blue",

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) >= 7 && DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) <= 14, "Yellow",

        DATEDIFF(DATEVALUE('Table'[Datevalue]), NOW(), DAY) >= 14, "Red",

        ""
    )

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks for the response @PhilipTreacy 

my output for the column is numbers 1,2,3,4,5

 

I wil give conditional formatting based on numbers. 

and all these week calculations are based on Today

AllisonKennedy
Super User
Super User

@RENJITH_R_S  If you want a new column, you can use this formula:

 

Colour column =

VAR _DVweek = WEEKNUM(table[DateValue])

VAR _Todayweek = WEEKNUM(Today())

RETURN

SWITCH(TRUE()

, table[Value] = "d" , "Green"

, table[Value] = "a", "Grey"

, _DVweek = _Todayweek , "Blue"

, _DVweek +1 = _Todayweek, "Yellow"

,  "Red"

)

 

Note: This uses week number, so sun-mon. If you want rolling week, you can ammend the formula slightly and use DATEDIFF function.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thanks for the response @AllisonKennedy 

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.