Count Remaining Days per Fiscal Month

半城伤御伤魂 提交于 2020-04-30 06:29:22

问题


Based on this Post I am building a fiscal calendar:

The following Dax generates a DAX Calendar:

Calendar = 
VAR BaseCalendar =
    CALENDAR ( DATE ( 2016; 1; 1 ); DATE ( 2025; 12; 31 ) )
RETURN
    GENERATE (
        BaseCalendar;
        VAR BaseDate = [Date]
        VAR Year =
            YEAR ( BaseDate )
        VAR MonthNumber =
            MONTH ( BaseDate )
        VAR WeekNumber =
            WEEKNUM ( BaseDate )
        VAR FWeek =
            WEEKNUM ( BaseDate; 21 )
        RETURN
            ROW (
                "Day"; BaseDate;
                "Year"; Year;
                "Month Number"; MonthNumber;
                "Month"; FORMAT ( BaseDate; "mmmm" );
                "Year Month"; FORMAT ( BaseDate; "yyyy-mm" );
                "Day of Week"; FORMAT ( BaseDate; "dddd" );
                "Day of Week Short"; FORMAT ( BaseDate; "ddd" );
                "Week"; WeekNumber;
                "Year-Week"; Year & "-" & WeekNumber;
                "Fiscal Week"; FWeek;
                "Fiscal Month Short"; SWITCH (
                    TRUE ();
                    FWeek IN { 1; 2; 3; 4 }; "Jan";
                    FWeek IN { 5; 6; 7; 8 }; "Feb";
                    FWeek IN { 9; 10; 11; 12; 13 }; "Mar";
                    FWeek IN { 14; 15; 16; 17 }; "Apr";
                    FWeek IN { 18; 19; 20; 21 }; "May";
                    FWeek IN { 22; 23; 24; 25; 26 }; "Jun";
                    FWeek IN { 27; 28; 29; 30 }; "Jul";
                    FWeek IN { 31; 32; 33; 34 }; "Aug";
                    FWeek IN { 35; 36; 37; 38; 39 }; "Sep";
                    FWeek IN { 40; 41; 42; 43 }; "Oct";
                    FWeek IN { 44; 45; 46; 47 }; "Nov";
                    FWeek IN { 48; 49; 50; 51; 52; 53 }; "Dec"
            )
    )

Now I need a column that shows me remaining days for the respective fiscal month for every date. I would suggest I need a first column, that accumulates the working days per month. Then I need a second column that subtract this value from the total sum for the corresponding month.

How would you add build that into the calendar in the same approach provided above?


回答1:


Depending on what you define as a working day. I'm presuming it is Mon-Fri You need a new column added to your above DAX to return a 1 or 0

IsWeekDay = SWITCH(TRUE(), WEEKDAY(Calendar[Date], 2) <= 5, 1, 0)

So it will return 1 for Mon-Fri, 0 for anything else. Next add a column for your month start date, I'm using the Calendar Month in this example:

MonthStart = STARTOFMONTH(Calendar[Date])

For a date of 04/04/2020, it will return a date of 01/04/2020

The next new column should sum up the working days using EARILER

Working Days = 
CALCULATE ( SUM('Calendar'[IsWeekDay]),
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] >= EARLIER ( 'Calendar'[Date] )
            &&  EARLIER('Calendar'[MonthStart]) = STARTOFMONTH('Calendar'[Date])
    )
)

You'll have to adjust it for your Fiscal Month Start Date



来源:https://stackoverflow.com/questions/61425462/count-remaining-days-per-fiscal-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!