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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
BowerPI
Regular Visitor

Variance between months, based on filtered table

Hello!

 

I'm new to PowerBI so any help would be appreciated 🙂

 

I have a source data table in PowerBi that looks something like this (Unfortunately can't share actual file due to confidentiality reasons):

BowerPI_6-1707435551686.png

 

This is just an example, but basically for a given site, there are multiple meter IDs, and each meter has a Room ID (room that it services).

 

I've managed to create a visual that summarises the total consumption of each RoomID at each month of the year for a given site.

 

BowerPI_4-1707434756438.png

 

I'm trying to find the variance month to month, and display it in a similar format for each site. E.g. based on the image directly above, to produce something like this:

BowerPI_5-1707435340449.png

Where ~3050% = (996226.55 - 31624.55)/31624.55 * 100% 

and

~ -3.75% = difference in consumption between May and June for Room ID: A010.

 

Will it require using DAX or creating a new table? If you know how to go about it please let me know 🙂

 

Thank you!

1 ACCEPTED SOLUTION

Hi @BowerPI ,

Change the 

'dcs_test_data_2'[month].[Month]

into this:

'dcs_test_data_2'[month].[MonthNo]

[month].[Month] returns words for each month, and [month].[MonthNo] returns a number for each month

vjunyantmsft_0-1707718078541.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_1-1707453754231.png

 

 

Jihwan_Kim_0-1707453717801.png

 

Consumption measure: = 
SUM( Data[Consumption] )

 

OFFSET function (DAX) - DAX | Microsoft Learn

 

compare to prev month measure: =
VAR _currentmonth = [Consumption measure:]
VAR _prevmonth =
    CALCULATE (
        [Consumption measure:],
        OFFSET (
            -1,
            ALL ( 'Calendar'[Year-Month sort], 'Calendar'[Year-Month] ),
            ORDERBY ( 'Calendar'[Year-Month sort], ASC )
        )
    )
RETURN
    IF (
        NOT ISBLANK ( _currentmonth ),
        IF (
            NOT ISBLANK ( _prevmonth ),
            FORMAT ( DIVIDE ( _currentmonth - _prevmonth, _prevmonth ), "#0.00%" ),
            FORMAT ( 0, "#0" )
        )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks for the reply. I am getting all 0% for my results but it may be due to my formatting of my "date" field. My date formatting is as follows: "Saturday, 30 April, 2022", "Tuesday, 31 May, 2022". How could I update your code above?

v-junyant-msft
Community Support
Community Support

Hi @BowerPI ,

Please try to use this DAX to create a new column:

Column = 
VAR CURRENT_ROOM = 'Table'[Room ID]
VAR CURRENT_MONTH = 'Table'[Month].[MonthNo]
VAR PREVIOUS_MONTH = CURRENT_MONTH - 1
VAR PREVIOUS_consumption = 
CALCULATE(
    SUM('Table'[consumption]),
    FILTER(
        'Table',
        'Table'[Room ID] = CURRENT_ROOM && 'Table'[Month].[MonthNo] = PREVIOUS_MONTH
    )
)
RETURN
DIVIDE(('Table'[consumption] - PREVIOUS_consumption), PREVIOUS_consumption)

The final output is as below:

vjunyantmsft_0-1707453310709.png

vjunyantmsft_1-1707453415641.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your response. I tried implementing the above, but I get the following error as you can see:

BowerPI_1-1707713548986.png

Here "RoomID" has been subbed in and "calc_kwhr" is just consumption. My date formatting is as follows: "Saturday, 30 April, 2022", "Tuesday, 31 May, 2022". How could I update your code above?

 

 

Hi @BowerPI ,

Change the 

'dcs_test_data_2'[month].[Month]

into this:

'dcs_test_data_2'[month].[MonthNo]

[month].[Month] returns words for each month, and [month].[MonthNo] returns a number for each month

vjunyantmsft_0-1707718078541.png


Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the suggestion. Another complication is that the months actually span over 3 years. When I use MonthNo. and check the output for current and previous month, I get very large numbers, where previous month no. is not equal to current month - 1.

 

There is something to do with the monthNo. but I can't figure out how it is working. Do you have any ideas?

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.