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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
sekinod
Helper II
Helper II

Month End Value and Current Date Value

I have the following data which contains the target value for each month-end.

cap 1.PNG

So, what I want is when selecting a particular date on the slicer, All the months' end value for each month up to  the selected date and the year, and the selected date at the last row. For example, if I select 12/14/2018, the following table should be created. Only the last row value change.

 

targtet.PNG

The last row value of the table change from original data because the value should be multiplied by (working days up to that date/total working days in the month) if the date is not equal to the month's end date.

 

Data Sheet:

TargetData 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You can't add the slicer date easily, so here is a second measure you can add to the visual to show that.

 

MaxDate in Target =
VAR seldate =
    MIN ( Dates[Date] )
VAR eomdate =
    CALCULATE (
        MAX ( Target[Date] ),
        ALL ( Dates )
    )
RETURN
    IF (
        seldate < eomdate,
        seldate,
        eomdate
    )
 
Regards,
Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

10 REPLIES 10
mahoneypat
Microsoft Employee
Microsoft Employee

You can't add the slicer date easily, so here is a second measure you can add to the visual to show that.

 

MaxDate in Target =
VAR seldate =
    MIN ( Dates[Date] )
VAR eomdate =
    CALCULATE (
        MAX ( Target[Date] ),
        ALL ( Dates )
    )
RETURN
    IF (
        seldate < eomdate,
        seldate,
        eomdate
    )
 
Regards,
Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Microsoft Employee
Microsoft Employee

I did use your pbix but it did not have any visuals, so I couldn't see how you were selecting the date.  Here is my file.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Dear @mahoneypat 

Values getting for measure is correct, but the last column date also shown as monthend date it should be selected date.

Thank you

Anonymous
Not applicable

Hi @sekinod,

In fact, current power bi not support to create dynamic calculated columns based on filter/slicer. They are works on different data level and you can't use the child level filter to affect their parent.

Notice: the data level of power bi.
Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view wiht virtual tables (measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

mahoneypat
Microsoft Employee
Microsoft Employee

I saw same behavior with CALENDAR, so went another way.  Please try this expression instead.  Let me know if it works or if any questions on what it's doing.  This seems to work in a table visual with your Target[Date].

 

Target to Selected Date =
VAR vDateValue =
    MIN ( Dates[Date] )
VAR vTgtMonthDate =
    CALCULATE (
        MIN ( Target[Date] ),
        ALL ( Dates )
    )
VAR vTgtMonthStart =
    DATE ( YEAR ( vTgtMonthDate )MONTH ( vTgtMonthDate )1 )
VAR vEndDate =
    IF (
        vTgtMonthDate < vDateValue,
        vTgtMonthDate,
        vDateValue
    )
VAR vWkDaysPast =
    CALCULATE (
        SUM ( Dates[Working Day] ),
        FILTER (
            ALL ( Dates[Date] ),
            Dates[Date] >= vTgtMonthStart
                && Dates[Date] <= vEndDate
        )
    )
VAR vWkDays =
    CALCULATE (
        SUM ( Dates[Working Day] ),
        FILTER (
            ALL ( Dates[Date] ),
            Dates[Date] >= vTgtMonthStart
                && Dates[Date] <= vTgtMonthDate
        )
    )
VAR vMonthTgt =
    CALCULATE (
        SUM ( Target[Amount] ),
        ALL ( Dates )
    )
VAR result =
    DIVIDE (
        vWkDaysPast * vMonthTgt,
        vWkDays
    )
RETURN
    result

 

mahoneypat_0-1607707672170.png

 

I used a date slicer on Dates[Date] and used the min value in the expression.  Not sure how you are selected the date.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Dear @mahoneypat 

It didn't work, visual is empty. If you don't mind could you do it on sample.pbix file I have provided.

Thank you

mahoneypat
Microsoft Employee
Microsoft Employee

Since you have a relationship between Dates and DT, please try this instead.  If it doesn't work, please send a link to your pbix (or a mock up of it), and I can get it working on this end.

 

Tgt = 
VAR vDateValue =
    MIN ( Dates[Date] )
VAR vTgtMonthDate =
    CALCULATE( MIN( DT[Date] ), ALL( Dates ), VALUES( DT[Date]))
VAR vWkDays =
    FILTER (
        CALENDAR (
            DATE ( YEAR ( vTgtMonthDate ), MONTH ( vTgtMonthDate ), 1 ),
            EOMONTH (
                vTgtMonthDate,
                0
            )
        ),
        WEEKDAY ( [Date] )
            IN {
            2,
            3,
            4,
            5,
            6
        }
    )
VAR vWkDaysPast =
    FILTER (
        vWkDays,
        [Date] <= vDateValue
    )
VAR vMonthTgt =
    CALCULATE( MIN ( DT[Amount] ), ALL(Dates), VALUES(DT[Date]))
RETURN
    DIVIDE (
        COUNTROWS ( vWkDaysPast ) * vMonthTgt,
        COUNTROWS ( vWkDays )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Dear @mahoneypat 

please find sample pbix file here sample.pbix 

 

Thanks

mahoneypat
Microsoft Employee
Microsoft Employee

Here is a measure that should work in a table visual with your Date column from the table you've shown.  I called it targets, so change it to your actual table name.  This assumes you are using your Date table for the slicer but that there is no relationship to the targets table. 

 

Tgt =
VAR vDateValue =
    MIN ( 'Date'[Date] )
VAR vTgtMonthDate =
    MIN ( Targets[Date] )
VAR vWkDays =
    FILTER (
        CALENDAR (
            DATE ( YEAR ( vTgtMonthDate )MONTH ( vTgtMonthDate )1 ),
            EOMONTH (
                vTgtMonthDate,
                0
            )
        ),
        WEEKDAY ( [Date] )
            IN {
            2,
            3,
            4,
            5,
            6
        }
    )
VAR vWkDaysPast =
    FILTER (
        vWkDays,
        [Date] <= vDateValue
    )
VAR vMonthTgt =
    MIN ( Targets[ Amount ] )
RETURN
    DIVIDE (
        COUNTROWS ( vWkDaysPast ) * vMonthTgt,
        COUNTROWS ( vWkDays )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Dear @mahoneypat 

This error  I get after creating the measure

error.PNG

This is my data model

 

model.PNG

 

This is the modified dax expression I used

Tgt = 
VAR vDateValue =
    MIN ( Dates[Date] )
VAR vTgtMonthDate =
    MIN ( DT[Date] )
VAR vWkDays =
    FILTER (
        CALENDAR (
            DATE ( YEAR ( vTgtMonthDate ), MONTH ( vTgtMonthDate ), 1 ),
            EOMONTH (
                vTgtMonthDate,
                0
            )
        ),
        WEEKDAY ( [Date] )
            IN {
            2,
            3,
            4,
            5,
            6
        }
    )
VAR vWkDaysPast =
    FILTER (
        vWkDays,
        [Date] <= vDateValue
    )
VAR vMonthTgt =
    MIN ( DT[Amount] )
RETURN
    DIVIDE (
        COUNTROWS ( vWkDaysPast ) * vMonthTgt,
        COUNTROWS ( vWkDays )
    )

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors