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
Anonymous
Not applicable

Measure that calculates values on current date

There is a measure that calculates some values(underline with a red line in measure)

image_2021-07-06_17-16-45.png

I need to change this calculation. For example if we have values that before current date, then we should calculate it for current month.

On the picture we have values on May, but now is July(according to max date of [period]), and I need to move this values to current date.

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Since I don't have your data, I have created a template based on the information you provided, which you can refer to.

If you want the month before this month with data,take below:

test = 
VAR current_date =
    MAX ( 'Table'[period] )
VAR pervious_value =
    CALCULATE (
        [number2],
        FILTER ( ALL ( 'Table' ), 'Table'[period] < current_date )
    )
VAR THISMONBLANK =
    CALCULATE (
        MAXX ( 'Table', [number2] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[period] < MONTH ( TODAY () )
                && [number2] <> BLANK ()
        )
    )
VAR TEST1 =
    IF (
        current_date > MONTH ( TODAY () ),
        BLANK (),
        IF (
            current_date = MONTH ( TODAY () )
                && pervious_value = BLANK (),
            THISMONBLANK,
            pervious_value
        )
    )
RETURN
    TEST1

 

 

vluwangmsft_0-1627370643220.png

 

And if you want only this month with data. Use the below :

test1 = 
VAR current_date =
    MAX ( 'Table'[period] )
VAR pervious_value =
    CALCULATE (
        [number2],
        FILTER ( ALL ( 'Table' ), 'Table'[period] < current_date )
    )
VAR THISMONBLANK =
    CALCULATE (
        MAXX ( 'Table', [number2] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[period] < MONTH ( TODAY () )
                && [number2] <> BLANK ()
        )
    )
VAR TEST1 =
    IF (
        current_date > MONTH ( TODAY () )|| current_date < MONTH ( TODAY () ),
        BLANK (),
        IF (
            current_date = MONTH ( TODAY () )
                && pervious_value = BLANK (),
            THISMONBLANK,
            pervious_value
        )
    )
RETURN
    TEST1

vluwangmsft_1-1627370764583.png

 

 

 

You could download my pbix file if you need!

 

 

 

 

 

 

 

 

Best Regards

Lucien

View solution in original post

2 REPLIES 2
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

Since I don't have your data, I have created a template based on the information you provided, which you can refer to.

If you want the month before this month with data,take below:

test = 
VAR current_date =
    MAX ( 'Table'[period] )
VAR pervious_value =
    CALCULATE (
        [number2],
        FILTER ( ALL ( 'Table' ), 'Table'[period] < current_date )
    )
VAR THISMONBLANK =
    CALCULATE (
        MAXX ( 'Table', [number2] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[period] < MONTH ( TODAY () )
                && [number2] <> BLANK ()
        )
    )
VAR TEST1 =
    IF (
        current_date > MONTH ( TODAY () ),
        BLANK (),
        IF (
            current_date = MONTH ( TODAY () )
                && pervious_value = BLANK (),
            THISMONBLANK,
            pervious_value
        )
    )
RETURN
    TEST1

 

 

vluwangmsft_0-1627370643220.png

 

And if you want only this month with data. Use the below :

test1 = 
VAR current_date =
    MAX ( 'Table'[period] )
VAR pervious_value =
    CALCULATE (
        [number2],
        FILTER ( ALL ( 'Table' ), 'Table'[period] < current_date )
    )
VAR THISMONBLANK =
    CALCULATE (
        MAXX ( 'Table', [number2] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[period] < MONTH ( TODAY () )
                && [number2] <> BLANK ()
        )
    )
VAR TEST1 =
    IF (
        current_date > MONTH ( TODAY () )|| current_date < MONTH ( TODAY () ),
        BLANK (),
        IF (
            current_date = MONTH ( TODAY () )
                && pervious_value = BLANK (),
            THISMONBLANK,
            pervious_value
        )
    )
RETURN
    TEST1

vluwangmsft_1-1627370764583.png

 

 

 

You could download my pbix file if you need!

 

 

 

 

 

 

 

 

Best Regards

Lucien

amitchandak
Super User
Super User

@Anonymous , based on what I got. Assume month are coming from Date/calendar table.

Measure for values of last available month

 

measure =
var _max = calculate(max(Table[Date]), filter('Table', 'Table'[Date] <= Max('Date'[Date]))
return
calculate(sum(Table[Value]), filter(all('Date') , eomonth('Date'[Date],0) = eomonth(_max,0)))

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.

Top Solution Authors