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
billyrich83
Frequent Visitor

Help required

Hi all I have the below calculation for fiscal week numbers, however it start the fiscal canlendar to start on the 1st April each year and I need it to start on the 1st Monday in April each year. 

 

Can anyone suggest how to change this to get the right outcome? 

Fiscal Week = 
--Inputs--
VAR WeekStartsOn = "mon"
VAR FiscalStartMonth = 4

--Calculation--
VAR FiscalFirstDay = 
    IF(
        MONTH('Date Table'[Date]) < FiscalStartMonth,
        DATE(
            YEAR('Date Table'[Date])-1,
            FiscalStartMonth,
            1
        ),
        DATE(
            YEAR('Date Table'[Date]),
            FiscalStartMonth,
            1
        )
    )
VAR FilteredTableCount = 
    COUNTROWS(
        FILTER(
            SELECTCOLUMNS(
                GENERATESERIES(
                    FiscalFirstDay,
                    'Date Table'[Date]
                ),
                "Dates",
                [Value]
            ),
        FORMAT([Dates],"ddd") = WeekStartsOn
        )
    )
VAR WeekNos = 
    IF(
        FORMAT(FiscalFirstDay,"ddd") <> WeekStartsOn,
        FilteredTableCount + 1,
        FilteredTableCount
    )
RETURN
    "Week " & WeekNos
5 REPLIES 5
v-xiaotang
Community Support
Community Support

Hi @billyrich83 

Try this, change the value in QUOTIENT to 2

vxiaotang_0-1644470369778.png

Have you solved this question? If you have solved the question, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

If you need more help, please let me know.

 

Best Regards,

Community Support Team _Tang

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

Thejeswar
Resident Rockstar
Resident Rockstar

Hi @billyrich83 ,
I just modified a little in your code and it worked

Create a new column as below

Start of Week = ('Date'[Date]+-1*WEEKDAY('Date'[Date],2)) + 1

 

Modified the DAX that you shared as follows

FiscalWeek = 
--Inputs--
VAR WeekStartsOn = "mon"
VAR FiscalStartMonth = 4

--Calculation--
VAR FiscalFirstDay = 
    IF(
        MONTH('Date'[Date]) < FiscalStartMonth,
        DATE(
            YEAR('Date'[Date])-1,
            FiscalStartMonth,
            1
        ),
        DATE(
            YEAR('Date'[Date]),
            FiscalStartMonth,
            1
        )
    )
VAR FilteredTableCount = 
    COUNTROWS(
            SELECTCOLUMNS(
                GENERATESERIES(
                    FiscalFirstDay,
                    'Date'[Date]
                ),
                "Dates",
                [Value]
            )
    )
VAR WeekNos = 
            QUOTIENT(FilteredTableCount+1, 7)
RETURN
    "Week " & WeekNos

 

 

Hi, 

 

Thanks for this, 1 small issue it's showing the first dayte as zero and I'm now a day behind in the calculation is there a way to fix this? it might be something I've done. 

 

Screenshot 2022-01-21 100221.png

When I checked the code, found that the hard coding that you have done works fine for one year (probably because you have hard coded based on that year) while it does not work for the other year. Have been busy since then. Hence unable to look into this further. May be someone else can get to help you with this.

amitchandak
Super User
Super User

@billyrich83 , Try these new columns

 

Start Of year = if(month([Date]) <4, date(year([Date])-1,4,1), date(year([Date])-1,4,1))


Start of Week = 'Date'[Date]+-1*WEEKDAY('Date'[Date]

 

FY Start of Week = minx(filter('Date', [Start of Week] >= [Start Of year]), [Start of Week])

 

FY Week No = quotient(datediff([FY Start of Week], [Date], day),7) +1

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.