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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
manojk_pbi
Helper IV
Helper IV

Need help to write DAX or measure

Hi Friends,

 

I am working on some data to represent the trends of % Change in Bugs. The change is always calculated for the current month & baseline will Janunary (opening counts). The baseline can be flexible sometime it can go to the previous years month. How can we write a DAX or measure where baseline month can be configure and % change can be calculated using the current data.

Please let me know if there are any suggesstions? It will be of great help.

For better understanding i am adding sample data and expected graph below

 

% Change formula = (Baseline Month Data - Current Month Data)/Baseline Month Data

Threshold Static - Expected % change 

 

MonthYearProductBugs% ChangeThreshold 100
Jan-24Product 1200  
Mar-24Product 11905%8%
Jan-24Product 2100  
Mar-24Product 2125-25%8%
Jan-24Product 3130  
Mar-24Product 311015%8%
Jan-24Product 4160  
Mar-24Product 41553%8%
Jan-24Product 520  
Mar-24Product 523-15%8%
Jan-24Product 640  
Mar-24Product 6385%8%

 

Expected output from above table :

manojk_pbi_0-1710433179852.png

 

Thanks,

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @manojk_pbi 

 

Custom Column Index in PowerQuery 

 

vyohuamsft_1-1710489560546.png

 

Then create new columns

vyohuamsft_2-1710489751480.png

Change =
VAR _perviousIndex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Index] < EARLIER ( 'Table'[Index] )
                && 'Table'[Product] = EARLIER ( 'Table'[Product] )
        )
    )
VAR _perviousBugs =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Bugs] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _perviousIndex )
    )
RETURN
    IF (
        _perviousBugs <> BLANK (),
        ( _perviousBugs - 'Table'[Bugs] ) / _perviousBugs
    )

 

Threshold = IF ( [MonthYear] = DATE(2024,3,24), 0.08, BLANK() )

 

Here is my preview:

 

vyohuamsft_3-1710489843147.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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
manojk_pbi
Helper IV
Helper IV

Hi @Anonymous ,

Thanks for you suggestion.

Since I am new to DAX queries, I couldn't understand the measure written to create a column. Is it assumed to be 2 values per product and then compared or can it work for N data points. 

Please can you elaborate bit more on this works 

Anonymous
Not applicable

Hi, @manojk_pbi 

 

Select New A Column on the modeling page

 

vyohuamsft_0-1710747400774.png

 

Or right-click on your table to create a column instead of selecting a metric. These two are not quite the same

 

vyohuamsft_1-1710747441314.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

This steps is clear. I didn't understand the logic of Change column how it works ? Is it fixed for 2 rows or can be used for N records

Anonymous
Not applicable

Hi, @manojk_pbi 

It can be used for N records.

You can search for documentation on the relationship between Measure and Calculated column, such as the link below:

Calculated Columns and Measures in DAX - SQLBI

 

Best Regards

Yongkang Hua

Thanks for your suggestions. I understood the logic now. 

 

As per logic, always the difference is calculated with current & previous record. This is once of the scenario, actually it should calculate change w.r.t to Jan'24 or Start of the Year or even better if it can be configured. 

Please could you help me with modified DAX for the same. 

 

Thanks in advance.

Anonymous
Not applicable

Hi, @manojk_pbi 

 

Custom Column Index in PowerQuery 

 

vyohuamsft_1-1710489560546.png

 

Then create new columns

vyohuamsft_2-1710489751480.png

Change =
VAR _perviousIndex =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Index] < EARLIER ( 'Table'[Index] )
                && 'Table'[Product] = EARLIER ( 'Table'[Product] )
        )
    )
VAR _perviousBugs =
    CALCULATE (
        SELECTEDVALUE ( 'Table'[Bugs] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _perviousIndex )
    )
RETURN
    IF (
        _perviousBugs <> BLANK (),
        ( _perviousBugs - 'Table'[Bugs] ) / _perviousBugs
    )

 

Threshold = IF ( [MonthYear] = DATE(2024,3,24), 0.08, BLANK() )

 

Here is my preview:

 

vyohuamsft_3-1710489843147.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.