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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Himanshu_1306
Helper V
Helper V

Dynamic Month1 and 2 calculations

Hi All,

 

I'm stuck on a calculated measure I'm trying to create and would need help here.

Problem Breakdown: 

On the last day of the quarter/Last day of the month, we need to ensure that Month 1 and Month 2 values are visible along with Month 3(which lies in the last month of quarter) values. If I dont select any flag for quarter/month last day then the measure is working fine.

I have created a measure below and it is working absolutely fine and giving me the correct value when I'm using either of my flags in the data ( is_last_fiscal_day_of_quarter or is_last_day_of_month). 

But the issue is that the data is not getting filtered when I'm using any other cuts from my table like if I'm trying to filter on a SVP/RVP etc the measure value is not filtering if I've applied either of the flags. Instead of ALL function I've tried using ALLSELECTED as well but its also not working.

Himanshu_1306_0-1747076503401.png

 



Expected Result: I want the measure to work with both the flags and without them also and data to get filtered by any cut in the dataset. 

I'm attaching a sample PBIX for reference. Quick Help would be highly appreciated.

PBIX LINK : https://drive.google.com/file/d/1BpMg28UgVwFRnGt6QEh0OqTwWOzXXkkW/view?usp=sharing

Measure Created:

Month1_CW_MTD_New =
VAR IsLastDayOfQuarter = SELECTEDVALUE(VW_D_DATE[IS_LAST_FISCAL_DAY_OF_QUARTER], FALSE)
VAR IsLastDayOfMonth   = SELECTEDVALUE(VW_D_DATE[IS_LAST_DAY_OF_MONTH], FALSE)
VAR CurrentMonth       = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Month])
VAR SelectedQuarter    = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER])

VAR IsSpecialDay =
    IsLastDayOfQuarter ||
    (IsLastDayOfMonth && CurrentMonth = 1)

VAR Month1EndValue =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        FILTER(
            ALL(VW_F_PIPELINE_HISTORY),
            VW_F_PIPELINE_HISTORY[Month] = 1 &&
            VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER] = SelectedQuarter &&
            VW_F_PIPELINE_HISTORY[is_last_day_of_fiscal_month] = TRUE()
        )
    )

VAR DailyValue =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        FILTER(
            VW_F_PIPELINE_HISTORY,
            VW_F_PIPELINE_HISTORY[Month] = 1
        )
    )

RETURN
IF(
    IsSpecialDay,
    Month1EndValue,
    DailyValue
)
1 ACCEPTED SOLUTION

@v-csrikanth Thanks for trying but I managed to achieve the desired result myself using the below approach.

The measure you shared wont work because of the flag condition. Suppose I want Month1 last day's data to be seen when I'm using the flah "Is_Last_Day_of_Fiscal_Quarter" but since that day doesn't fall under the last fiscal month of quarter the measure you tried wont work.

I created a seperate flag table using the below DAX and altered my measure to use this flag table. 

Let me know in case any further help/clarification is needed

Flag_Table = DATATABLE("Flag", BOOLEAN, { { TRUE }, { FALSE } })

Himanshu_1306_0-1749556339368.png

This way I'm able to achieve the desired result.

Month1_CW =
VAR SelectedFlag = SELECTEDVALUE(Flag_Table[Flag], FALSE)
VAR CurrentDS = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[DS])
VAR CurrentMonth = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Month])
VAR CurrentQuarter = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER])
VAR FiscalYear = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Fiscal Year])

-- 1. Check if current DS is a quarter-end date
VAR IsQuarterEndDate =
    CALCULATE(
        MAXX(
            FILTER(
                ALL(VW_F_PIPELINE_HISTORY),
                VW_F_PIPELINE_HISTORY[DS] = CurrentDS
            ),
            IF(VW_F_PIPELINE_HISTORY[is_last_day_of_fiscal_quarter], 1, 0)
        )
    ) = 1

-- 2. Get last day of Month1 in that quarter
VAR LastDayOfMonth1InQuarter =
    CALCULATE(
        MAX(VW_F_PIPELINE_HISTORY[DS]),
        FILTER(
            ALL(VW_F_PIPELINE_HISTORY),
            VW_F_PIPELINE_HISTORY[Month] = 1 &&
            VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER] = CurrentQuarter &&
            VW_F_PIPELINE_HISTORY[Fiscal Year] = FiscalYear
        )
    )

-- 3. Get CW_MTD value for that Month1 day, preserve all filters except DS
VAR Month1Value =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        FILTER(
            ALL(VW_F_PIPELINE_HISTORY[DS]),
            VW_F_PIPELINE_HISTORY[DS] = LastDayOfMonth1InQuarter
        )
    )

-- 4. Show daily values if flag is false and it's Month1
VAR ShowDaily =
    NOT SelectedFlag &&
    CurrentMonth = 1 &&
    CurrentDS <= TODAY()

-- Final Output
RETURN
SWITCH(
    TRUE(),
    SelectedFlag && IsQuarterEndDate, Month1Value,
    ShowDaily, SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
    BLANK()
)

View solution in original post

8 REPLIES 8
v-csrikanth
Community Support
Community Support

Hi @Himanshu_1306 

We haven't heard from you since last response and just wanted to check whether the solution provided has worked for you. If yes, please Accept as Solution to help others benefit in the community.
Thank you.

If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.

@v-csrikanth Thanks for trying but I managed to achieve the desired result myself using the below approach.

The measure you shared wont work because of the flag condition. Suppose I want Month1 last day's data to be seen when I'm using the flah "Is_Last_Day_of_Fiscal_Quarter" but since that day doesn't fall under the last fiscal month of quarter the measure you tried wont work.

I created a seperate flag table using the below DAX and altered my measure to use this flag table. 

Let me know in case any further help/clarification is needed

Flag_Table = DATATABLE("Flag", BOOLEAN, { { TRUE }, { FALSE } })

Himanshu_1306_0-1749556339368.png

This way I'm able to achieve the desired result.

Month1_CW =
VAR SelectedFlag = SELECTEDVALUE(Flag_Table[Flag], FALSE)
VAR CurrentDS = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[DS])
VAR CurrentMonth = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Month])
VAR CurrentQuarter = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER])
VAR FiscalYear = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Fiscal Year])

-- 1. Check if current DS is a quarter-end date
VAR IsQuarterEndDate =
    CALCULATE(
        MAXX(
            FILTER(
                ALL(VW_F_PIPELINE_HISTORY),
                VW_F_PIPELINE_HISTORY[DS] = CurrentDS
            ),
            IF(VW_F_PIPELINE_HISTORY[is_last_day_of_fiscal_quarter], 1, 0)
        )
    ) = 1

-- 2. Get last day of Month1 in that quarter
VAR LastDayOfMonth1InQuarter =
    CALCULATE(
        MAX(VW_F_PIPELINE_HISTORY[DS]),
        FILTER(
            ALL(VW_F_PIPELINE_HISTORY),
            VW_F_PIPELINE_HISTORY[Month] = 1 &&
            VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER] = CurrentQuarter &&
            VW_F_PIPELINE_HISTORY[Fiscal Year] = FiscalYear
        )
    )

-- 3. Get CW_MTD value for that Month1 day, preserve all filters except DS
VAR Month1Value =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        FILTER(
            ALL(VW_F_PIPELINE_HISTORY[DS]),
            VW_F_PIPELINE_HISTORY[DS] = LastDayOfMonth1InQuarter
        )
    )

-- 4. Show daily values if flag is false and it's Month1
VAR ShowDaily =
    NOT SelectedFlag &&
    CurrentMonth = 1 &&
    CurrentDS <= TODAY()

-- Final Output
RETURN
SWITCH(
    TRUE(),
    SelectedFlag && IsQuarterEndDate, Month1Value,
    ShowDaily, SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
    BLANK()
)
v-csrikanth
Community Support
Community Support

HI @Himanshu_1306 
Based on the attached pbix file please go throught and try the below measure that meets your rquirements.

The function ALL and ALL Selected, override the filters thats why the existing measure wouldnt work.

You can use a combination of Remove filters and Keep filters respecting existing filters (like SVP/RVP).

 

Try this measure:

 

Month1_CW_MTD_New =
VAR IsLastDayOfQuarter = SELECTEDVALUE(VW_D_DATE[IS_LAST_FISCAL_DAY_OF_QUARTER], FALSE)
VAR IsLastDayOfMonth   = SELECTEDVALUE(VW_D_DATE[IS_LAST_DAY_OF_MONTH], FALSE)
VAR CurrentMonth       = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Month])
VAR SelectedQuarter    = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER])

 

VAR IsSpecialDay =
    IsLastDayOfQuarter ||
    (IsLastDayOfMonth && CurrentMonth = 1)

 

VAR Month1EndValue =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        REMOVEFILTERS(VW_F_PIPELINE_HISTORY[is_last_day_of_fiscal_month]),
        FILTER(
            ALL(VW_D_DATE),
            VW_D_DATE[is_last_day_of_fiscal_month] = TRUE()
        ),
        KEEPFILTERS(
            VW_F_PIPELINE_HISTORY[Month] = 1 &&
            VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER] = SelectedQuarter
        )
    )

 

VAR DailyValue =
    CALCULATE(
        SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
        KEEPFILTERS(
            VW_F_PIPELINE_HISTORY[Month] = 1
        )
    )

 

RETURN
IF(
    IsSpecialDay,
    Month1EndValue,
    DailyValue
)



If the issue has been resolved, can you mark the post as resolved. If you're still experiencing challenges, please feel free to let us know and we'll be happy to continue to help!
Looking forward to your reply!

Best Regards,
Community Support Team _ C Srikanth.

techies
Super User
Super User

Hi @Himanshu_1306 please try this

 

Month1_CW_MTD_Newf =
VAR IsLastDayOfQuarter = SELECTEDVALUE(VW_D_DATE[IS_LAST_FISCAL_DAY_OF_QUARTER], FALSE)
VAR IsLastDayOfMonth = SELECTEDVALUE(VW_D_DATE[IS_LAST_DAY_OF_MONTH], FALSE)
VAR CurrentMonth = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[Month])
VAR SelectedQuarter = SELECTEDVALUE(VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER])

VAR IsSpecialDay =
IsLastDayOfQuarter ||
(IsLastDayOfMonth && CurrentMonth = 1)

VAR Month1EndValue =
CALCULATE(
SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
KEEPFILTERS(VW_F_PIPELINE_HISTORY),
FILTER(
VW_F_PIPELINE_HISTORY,
VW_F_PIPELINE_HISTORY[Month] = CurrentMonth &&
VW_F_PIPELINE_HISTORY[FISCAL_YEAR_QUARTER] = SelectedQuarter &&
VW_F_PIPELINE_HISTORY[is_last_day_of_fiscal_month] = TRUE()
)
)

VAR DailyValue =
CALCULATE(
SUM(VW_F_PIPELINE_HISTORY[CW_MTD]),
FILTER(
VW_F_PIPELINE_HISTORY,
VW_F_PIPELINE_HISTORY[Month] = 1
)
)

RETURN
IF(
IsSpecialDay,
Month1EndValue,
DailyValue
)

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

I've tried using KEEPFILTERS as a function. If I use the above measure I'm getting numbers for last of the month 1and month 2 when I use is_last_day_fiscal_quarter = TRUE but the numbers I'm getting is wrong. Ideally I should get $3.10M in Month 1 and $8.07M in Month 2 as values when I select is_last_day_fiscal_quarter = True.

Using Fiscal_Quarter Flag ( Wrong Numbers):

Himanshu_1306_0-1747112960345.png


Correct Numbers:

Himanshu_1306_1-1747113027962.png

 

Let me know if you find any solution. I'm still stuck on this.

I've attached the link to the PBIX file as well.

ok

― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
Himanshu_1306
Helper V
Helper V

Objective: Dynamic Monthly CW_MTD Values by Flags

Need to create dynamic logic for each fiscal month (Month 1 and 2) that:

  1. On Daily View (No Flags):

    • Show the daily CW_MTD value for each date within the respective fiscal month.

  2. When a Flag is Used (Month-End or Quarter-End):

    • Show the final CW_MTD value of that fiscal month, only if:

      • The row belongs to that month (Month 1 or 2), and

      • The flag (IS_LAST_DAY_OF_MONTH or IS_LAST_FISCAL_DAY_OF_QUARTER) is set to TRUE.

  3. Able to filter data on any cuts in the dataset.

    Note:
    Month 3 uses a simple calculation and is giving correct value and filtering is also working fine. Need to create seperate measures for Month 1 and Month 2

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors