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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.