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

Trend DAX calculation in Matrix/Column Chart

Here is my source data:

andrewseaman_0-1602631588489.png

 

Here is the data aggregated in a table/bar chart:

andrewseaman_1-1602631664613.png

andrewseaman_2-1602631726469.png

What I need to create is a Trend calculation like this:

andrewseaman_3-1602631750871.png

I can append "Q4 - Trend" to the dataset, but I can't figure out how to populate the values using DAX.  In the actual dataset the user may filter down on results so a formula in excel would not be dynamic.  Any ideas?

 

andrewseaman_5-1602631842634.png

 

 

 

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

Hi @Anonymous ,

 

You may create a separate table and two measures for the visual.

 

1.Create a separate table by entering data. Quarter column is sorted by Sort column.

2.png3.png

 

2.Create two measures.

Margin Measure = 
VAR _count =
    CALCULATE ( COUNT ( 'Table'[Quarter] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
RETURN
    SWITCH (
        MAX ( 'Table (2)'[Quarter] ),
        "Q4-Trend",
            SWITCH (
                _count,
                1,
                    CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3,
                2,
                    CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3 / 2,
                3, CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
            ),
        "Q1", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q1" ) ),
        "Q2", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q2" ) ),
        "Q3", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q3" ) ),
        "Q4", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
    )
Sales Measure = 
VAR _count =
    CALCULATE ( COUNT ( 'Table'[Quarter] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
RETURN
    SWITCH (
        MAX ( 'Table (2)'[Quarter] ),
        "Q4-Trend",
            SWITCH (
                _count,
                1,
                    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3,
                2,
                    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3 / 2,
                3, CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
            ),
        "Q1", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q1" ) ),
        "Q2", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q2" ) ),
        "Q3", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q3" ) ),
        "Q4", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
    )

 

3.The visual is this.

4.png

 

 

You can check more details from here.

 

 

 

Best Regards,

Stephen 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

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You may create a separate table and two measures for the visual.

 

1.Create a separate table by entering data. Quarter column is sorted by Sort column.

2.png3.png

 

2.Create two measures.

Margin Measure = 
VAR _count =
    CALCULATE ( COUNT ( 'Table'[Quarter] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
RETURN
    SWITCH (
        MAX ( 'Table (2)'[Quarter] ),
        "Q4-Trend",
            SWITCH (
                _count,
                1,
                    CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3,
                2,
                    CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3 / 2,
                3, CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
            ),
        "Q1", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q1" ) ),
        "Q2", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q2" ) ),
        "Q3", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q3" ) ),
        "Q4", CALCULATE ( SUM ( 'Table'[Margin] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
    )
Sales Measure = 
VAR _count =
    CALCULATE ( COUNT ( 'Table'[Quarter] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
RETURN
    SWITCH (
        MAX ( 'Table (2)'[Quarter] ),
        "Q4-Trend",
            SWITCH (
                _count,
                1,
                    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3,
                2,
                    CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) ) * 3 / 2,
                3, CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
            ),
        "Q1", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q1" ) ),
        "Q2", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q2" ) ),
        "Q3", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q3" ) ),
        "Q4", CALCULATE ( SUM ( 'Table'[Sales] ), FILTER ( 'Table', [Quarter] = "Q4" ) )
    )

 

3.The visual is this.

4.png

 

 

You can check more details from here.

 

 

 

Best Regards,

Stephen Tao

 

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

amitchandak
Super User
Super User

@Anonymous , Where is Q4 trend available. If it is another table, Either you need to append table. Or you need to common Dimension, which includes Q4 and Q4 trend. If it needs to calculated then what is logic behind it.

Anonymous
Not applicable

Here is the logic for Q4 Trend:

If we only have one value for Q4 then multiply by 3

andrewseaman_0-1602648541390.png

If we have 2 values for Q4, SUM Q4, then multiply by 3/2

andrewseaman_1-1602648617664.png

If we have 3 values for Q4 then set equal to the sum of Q4.

 

We are trying to see what our total forecast will be for the entire quarter based on the first 1 or 2 months.

 

 

 

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.