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
Anonymous
Not applicable

fiscal week belonging to only one month

Hi All,

I have a calendar table where the fiscal year start at November 1st each year, so for the FY18 the Fiscal Week W-1 goes from 01/11/2018 to 7/11/2018 and so on.

 

Knowing this, it is normal that a Fiscal Week is shared by two months (the end of a month and the beginning of other). Like in the example below, W-14 is placed in both January and February.

 

Calendar PBI.PNG

I do not want this to happened, I would like to keep a week number under a one month only. So, in this example 01/02/2018 should be W-15 and not W-14.

 

Any idea? I would appreciate this.

 

Many thanks,

José

1 ACCEPTED SOLUTION

OK, I got it.

 

First, slight adjustment to Switch 3, I was returning 1 for the first day of the month when it switches but that wasn't quite right, or I guess I could have used a <= in my other measure, either way:

 

 

Switch 3 = 
VAR __week = [Week]
VAR __table = SUMMARIZE(FILTER(ALL('Calendar'),[Week]=__week),[Week],[Month],"__count",COUNT([Date]))
VAR __count = COUNTROWS(__table)
VAR __min = MINX(__table,[Month])
VAR __max = IF(__count>1,MAXX(FILTER(ALL('Calendar'),[Week]=__week && [Month]=__min),[Date]),BLANK())
RETURN
IF(ISBLANK(__max),BLANK(),IF([Date]=__max,1,BLANK()))

Then this column uses the Switch 3 column to adjust the week appropriately:

 

Expected FW = 
VAR __date = [Date]
VAR __adjustment = SUMX(FILTER(ALL('Calendar'),[Date]<__date),[Switch 3])
RETURN [Week]+__adjustment

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Probably a solution but it would probably take just as much time to come up with it as it would to just manually type them in.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Been looking at this in my spare time. Still working but here is the first part, identifying which weeks span months:

 

Switch = 
VAR __week = [Week]
VAR __table = SUMMARIZE(FILTER(ALL('Calendar'),[Week]=__week),[Week],[MonthName],"__count",COUNT([Date]))
RETURN IF(COUNTROWS(__table)>1,1,BLANK())

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

And here is a bit of an improved one. 

 

Switch 2 = 
VAR __week = [Week]
VAR __table = SUMMARIZE(FILTER(ALL('Calendar'),[Week]=__week),[Week],[MonthName],"__count",COUNT([Date]))
VAR __count = COUNTROWS(__table)
VAR __min = IF(__count>1,MINX(FILTER(ALL('Calendar'),[Week]=__week),[Date]),BLANK())
RETURN
IF(ISBLANK(__min),BLANK(),IF([Date]=__min,1,BLANK()))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, sorry, this is probably the one that you want to use:

 

Switch 3 = 
VAR __week = [Week]
VAR __table = SUMMARIZE(FILTER(ALL('Calendar'),[Week]=__week),[Week],[Month],"__count",COUNT([Date]))
VAR __count = COUNTROWS(__table)
VAR __max = MAXX(__table,[Month])
VAR __min = IF(__count>1,MINX(FILTER(ALL('Calendar'),[Week]=__week && [Month]=__max),[Date]),BLANK())
RETURN
IF(ISBLANK(__min),BLANK(),IF([Date]=__min,1,BLANK()))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, I got it.

 

First, slight adjustment to Switch 3, I was returning 1 for the first day of the month when it switches but that wasn't quite right, or I guess I could have used a <= in my other measure, either way:

 

 

Switch 3 = 
VAR __week = [Week]
VAR __table = SUMMARIZE(FILTER(ALL('Calendar'),[Week]=__week),[Week],[Month],"__count",COUNT([Date]))
VAR __count = COUNTROWS(__table)
VAR __min = MINX(__table,[Month])
VAR __max = IF(__count>1,MAXX(FILTER(ALL('Calendar'),[Week]=__week && [Month]=__min),[Date]),BLANK())
RETURN
IF(ISBLANK(__max),BLANK(),IF([Date]=__max,1,BLANK()))

Then this column uses the Switch 3 column to adjust the week appropriately:

 

Expected FW = 
VAR __date = [Date]
VAR __adjustment = SUMX(FILTER(ALL('Calendar'),[Date]<__date),[Switch 3])
RETURN [Week]+__adjustment

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.