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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Spiedo
Helper I
Helper I

How to get the ISO year in DAX while ISO week looks so easy this seems to be hard

I created a calendar using DAX.

 

For instance for value 3-1-2021 i get week 53 using underneath DAX formula

"YearWeeknumber", FORMAT ([Date], "YYYY" ) & "/" & FORMAT(WEEKNUM ([Date],21), "00"),
 
But the year thrown back is 2021 while it should be year 2020/53.
Hopefully it is very simple, could you give a hint? it's appreciated.
1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @Spiedo ,

 

you could check when the month = 1 and the WEEKNUM > 50 then you should use year - 1, otherwise year.

Do you want to use it as a calculated column or as a measure?

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

10 REPLIES 10
Greg_Z
Regular Visitor

I am in a similar situation, but I need to calculate the first day of the ISO year with the week starting on Sunday.  For example (in Month/Day/Year):

The first day of the ISO year 2016 = 12/27/2015
The first day of the ISO year 2017 = 12/25/2016
The first day of the ISO year 2018 = 12/31/2017
etc.

I have calculated the ISO year, and the ISO weeks (i.e. if WEEKNUM = 53, then count it as the first week of the following year), but any of the MIN or MINX functions that I have tried to calculate the first day of the ISO year are only brining back the first day of the year for the first ISO year (i.e. 12/27/2015 is being returned for all years as the first ISO date of the year).

selimovd
Super User
Super User

Hey @Spiedo ,

 

you could check when the month = 1 and the WEEKNUM > 50 then you should use year - 1, otherwise year.

Do you want to use it as a calculated column or as a measure?

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Hi Everyone, 

 

i am preparing a new calander table in my power bi model,

Please could you advise me as how to calculate "ISO Date" in any calender in power BI. i really need this column, please help me.

Thank you. I was trying to implement it but the ADDCOLUMNS( ) does not seem to appreciate the IF statement. It seems like a column under the hood of ADDCOLUMNS() can't be an IF statement because i retyped it into a very simple IF statement first. Nevertheless i believe this workaround will help

Hey @Spiedo ,

 

it should also be possible with ADDCOLUMN. Can you share your measure?

 

Best regards

Denis

This is the beginning of the addcolumns, it specifically is about this column
"YearWeeknumber", FORMAT ([Date], "YYYY" ) & "/" & FORMAT(WEEKNUM ([Date],21), "00"),
 
If i turn an IF on it, I check the dates without FORMAT solely using the functions in the IF part, it is not accepted. Even if I use a very simple IF formule like IF(1>0;1;0) it is not accepted. I use PBI desktop october 2020 because we use this powerbi report server
 
 
Kalender = ADDCOLUMNS
        (
        CALENDAR (MIN(vCheckin_SupportCallList[Opened]),
        Now()),
        "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
        "Year", YEAR ( [Date] ),
        "Monthnumber", FORMAT ( [Date], "MM" ),
        "Weeknumber", FORMAT(WEEKNUM ([Date],21),00),
        "YearWeeknumber", FORMAT ([Date], "YYYY" ) & "/" & FORMAT(WEEKNUM ([Date],21), "00"),
        "YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),

Hey @Spiedo ,

 

try the following approach:

Kalender = 
ADDCOLUMNS(
        CALENDAR (MIN(vCheckin_SupportCallList[Opened]), Now()),
        "DateAsInteger", FORMAT ( [Date], "YYYYMMDD" ),
        "Year", YEAR ( [Date] ),
        "Monthnumber", FORMAT ( [Date], "MM" ),
        "Weeknumber", FORMAT(WEEKNUM ([Date],21),00),
        "YearWeeknumber", FORMAT ([Date], "YYYY" ) & "/" & FORMAT(WEEKNUM ([Date],21), "00"),
        "YearMonthnumber", FORMAT ( [Date], "YYYY/MM" ),
        "YearWeeknumber_New",
            SWITCH(TRUE(),
                MONTH([Date]) = 1 && WEEKNUM ([Date],21) > 50, YEAR([Date]) -1,
                MONTH([Date]) = 12 && WEEKNUM ([Date],21) = 1, YEAR([Date])+1,
                YEAR([Date])
            ) & "/" & FORMAT(WEEKNUM ([Date],21), "00")
)

 

This will give you the new year if week is week 1 in the old year:

selimovd_0-1622394005241.png

 

And also it will show you the old year when the week is the number of the old year:

selimovd_1-1622394119224.png

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Good morning

what do you mean by "vCheckin_SupportCallList[Opened]" ??

Best regards

That is the name of a database view containing many fields, also date fields

Thank you very much!

BTW:

This also solves the first week of the year if it is in the previous year, thank for this extra tweak!

 

Quite special there is no ISO year while an ISO week is available

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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