Forum Discussion

arp2's avatar
arp2
Helper II
1 year ago
Solved

Custom Fiscal Year error

I have a simple model in Power BI with two tables. I have a custom Fiscal Year Calendar Table which is Date Table. The FY starts in July and ends in June. The week starts on Saturday and ends on Friday. Last Friday of the month is monthly cutoff so month does not necessarily start on the 1st and does not necessarily ends on 30th / 31st. This Fiscal Year Table has several FYs (few years in the past & few years in the future). I have a Project Register which has Project Number, Project Creation Date and other fields. I want to create measures. I am trying to create a measures to calculate number of Projects created last week and number of Projects created Year to Date. It is not working as I get zero in both the measures. Please help me. 

(Example last week started on 14th Jun and ended on 20th Jun. Current FY is FY25 and it started on 29th Jun 2024 and will end on 27th Jun 2025.)

  • mark_endicott's avatar
    mark_endicott
    1 year ago

    arp2 - this will work for last week:

     

    VAR LastWeekStart =
        SELECTEDVALUE ( FYCalendar[WeekStart] ) - 7
    VAR LastWeekEnd =
        SELECTEDVALUE ( FYCalendar[WeekEnding] ) - 7
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( MasterProjListR02[Project Number] ),
            REMOVEFILTERS ( FYCalendar ),
            MasterProjListR02[Project Creation Date] >= LastWeekStart,
            MasterProjListR02[Project Creation Date] <= LastWeekEnd
        )

     

    and your measure for YTD will already work:

    see attached file

     

    If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

     

10 Replies

  • arp2 - At a guess, I would say you're not removing the filter context from your Fiscal Year Calendar and then re-adding the new context you wish to calculate. In order to do this you can use REMOVEFILTERS( Fiscal Year Calendar 

     

    Here's an example:

     

    VAR prev_week_start = SELECTEDVALUE( DateTable[Previous Week Start] )
    VAR prev_week_end = SELECTEDVALUE( DateTable[Previous Week End] )
    
    RETURN
    CALCULATE( [Measure], REMOVEFILTERS( DateTable ), Table[Date] >= prev_week_start && Table[Date] <= prev_week_end )

     

    However this is just a guess, because you've not provided your DAX that's returning 0 so.......

     

    If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

     

     

    • arp2's avatar
      arp2
      Helper II

      Thnx mark_endicott  I have pasted sample tables here above and the measures I have created (but not working). 

      ===
      ProjectsLastWeek2506 =
      VAR LastWeekStart =
          CALCULATE(MAX(FYCalendar[WeekStart]), ALL(FYCalendar))
      VAR LastWeekEnd =
          CALCULATE(MAX(FYCalendar[WeekEnding]), ALL(FYCalendar))
      RETURN
          CALCULATE(
              COUNTROWS(MasterProjListR02),
             MasterProjListR02[Project Creation Date] >= LastWeekStart,
              MasterProjListR02[Project Creation Date] <= LastWeekEnd
          )
      =====
       ============
      ProjectsYTD2506 =
      CALCULATE(
          COUNTROWS(MasterProjListR02),
          DATESYTD(FYCalendar[Date], "6/30")
      )
      ==========

       

      • mark_endicott's avatar
        mark_endicott
        Super User

        arp2 - is that exactly how your data is? 

         

        Because 11/7/2018 is not a valid date, but 11/07/2018 is. 

         

        Go to Power Query and check if the Project Creation Date column is formatted as a date, if it's not, do so and I suspect you'll either fix this column, or you'll see a column full of errors (I have fixed the first 4 rows below):

         

         

        Your DAX for the week calculation is missing the REMOVEFILTERS I suggested and your date parameters wont work, but the YTD one should work if we were using a date column. 

         

        If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

         

         

         

  • v-kpoloju-msft's avatar
    v-kpoloju-msft
    Community Support

    Hi arp2,

    Thank you for reaching out to the Microsoft fabric community forum. Also thanks to mark_endicott, for his insights on this thread. I reproduced the scenario, and it worked on my end. I used my sample data and successfully implemented it. Used line chart.

    outcome:

    I am also including .pbix file for your better understanding, please have a look into it:

    If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

    Thank you for using Microsoft Community Forum.

    • arp2's avatar
      arp2
      Helper II

      v-kpoloju-msft thanks for the reply. The Projects Created Last Week works perfectly, however, YTD is showing 6 whereas Projects YTD are 7. You may check and revert so that we can learn an alternative way otherwise Mark has already provided the solution.  

  • Project NumberProject NameProject Creation Date
    123ProjName17/30/2018
    124ProjName22/25/2016
    125ProjName33/20/2018
    126ProjName411/7/2018
    127ProjName56/26/2019
    128ProjName62/14/2016
    129ProjName710/27/2020
    130ProjName87/29/2024
    131ProjName97/29/2024
    132ProjName107/29/2024
    133ProjName117/29/2024
    134ProjName127/29/2024
    135ProjName137/29/2024
    136ProjName146/17/2025
    137ProjName157/29/2024
       
  • DateWeekEndingMonthCutoffFiscalYearWeekStart
    6/29/20247/5/20247/26/2024FY256/29/2024
    6/30/20247/5/20247/26/2024FY256/29/2024
    7/1/20247/5/20247/26/2024FY256/29/2024
    7/2/20247/5/20247/26/2024FY256/29/2024
    7/3/20247/5/20247/26/2024FY256/29/2024
    7/4/20247/5/20247/26/2024FY256/29/2024
    7/5/20247/5/20247/26/2024FY256/29/2024
    7/6/20247/12/20247/26/2024FY257/6/2024
    7/7/20247/12/20247/26/2024FY257/6/2024
    7/8/20247/12/20247/26/2024FY257/6/2024
    7/9/20247/12/20247/26/2024FY257/6/2024
    7/10/20247/12/20247/26/2024FY257/6/2024
    7/11/20247/12/20247/26/2024FY257/6/2024
    7/12/20247/12/20247/26/2024FY257/6/2024
    7/13/20247/19/20247/26/2024FY257/13/2024
    7/14/20247/19/20247/26/2024FY257/13/2024
    7/15/20247/19/20247/26/2024FY257/13/2024
    7/16/20247/19/20247/26/2024FY257/13/2024
    7/17/20247/19/20247/26/2024FY257/13/2024
    7/18/20247/19/20247/26/2024FY257/13/2024
    7/19/20247/19/20247/26/2024FY257/13/2024
    7/20/20247/26/20247/26/2024FY257/20/2024
    7/21/20247/26/20247/26/2024FY257/20/2024
    7/22/20247/26/20247/26/2024FY257/20/2024
    7/23/20247/26/20247/26/2024FY257/20/2024
    7/24/20247/26/20247/26/2024FY257/20/2024
    7/25/20247/26/20247/26/2024FY257/20/2024
    7/26/20247/26/20247/26/2024FY257/20/2024
    5/31/20256/6/20256/27/2025FY255/31/2025
    6/1/20256/6/20256/27/2025FY255/31/2025
    6/2/20256/6/20256/27/2025FY255/31/2025
    6/3/20256/6/20256/27/2025FY255/31/2025
    6/4/20256/6/20256/27/2025FY255/31/2025
    6/5/20256/6/20256/27/2025FY255/31/2025
    6/6/20256/6/20256/27/2025FY255/31/2025
    6/7/20256/13/20256/27/2025FY256/7/2025
    6/8/20256/13/20256/27/2025FY256/7/2025
    6/9/20256/13/20256/27/2025FY256/7/2025
    6/10/20256/13/20256/27/2025FY256/7/2025
    6/11/20256/13/20256/27/2025FY256/7/2025
    6/12/20256/13/20256/27/2025FY256/7/2025
    6/13/20256/13/20256/27/2025FY256/7/2025
    6/14/20256/20/20256/27/2025FY256/14/2025
    6/15/20256/20/20256/27/2025FY256/14/2025
    6/16/20256/20/20256/27/2025FY256/14/2025
    6/17/20256/20/20256/27/2025FY256/14/2025
    6/18/20256/20/20256/27/2025FY256/14/2025
    6/19/20256/20/20256/27/2025FY256/14/2025
    6/20/20256/20/20256/27/2025FY256/14/2025
    6/21/20256/27/20256/27/2025FY256/21/2025
    6/22/20256/27/20256/27/2025FY256/21/2025
    6/23/20256/27/20256/27/2025FY256/21/2025
    6/24/20256/27/20256/27/2025FY256/21/2025
    6/25/20256/27/20256/27/2025FY256/21/2025
    6/26/20256/27/20256/27/2025FY256/21/2025
    6/27/20256/27/20256/27/2025FY256/21/2025