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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
arunalle
New Member

Need to calculate next 3 quarters data along with selected quarter in the filter

Hi friends,

I have a requirement that I need to calculate next 3 quarters data along with selected quarter in the filter in a matrix visual. I have the quarter column in the form of "Q1 FY22". The fields that I used in the matrix visual are 

Rows : Category

Columns : Sales dates
Values : Sales amount

 

Example :1. If I select Q3 FY22 in the filter then need to calculate the sales amount for Q3 FY22, Q4 FY22, Q1 FY23, Q2 FY23.

Example :2. If I select Q2 FY24 in the filter then need to calculate the sales amount for Q2 FY24, Q3 FY24, Q4 FY24, Q1 FY25.

 

please suggest me with a perfect dax expression. thanks in advance

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

Hi  @arunalle ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a quarters dimenstion table as below(DO NOT create any relationship with the fact tables)

yingyinr_0-1655802517974.png

2. Create a calculated column to get the number in quarter field

QNum = VALUE ( RIGHT ( 'Table'[Quarter], 2 ) & MID ( 'Table'[Quarter], 2, 1 ) )

yingyinr_1-1655802592806.png

3. Create a measure as below to get the sales amount

Measure = 
VAR _selquarter =
    SELECTEDVALUE ( 'Quarters'[Quarter] )
VAR _selqnum =
    CALCULATE (
        MAX ( 'Table'[QNum] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Quarter] = _selquarter )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales amount] ),
        FILTER (
            'Table',
            'Table'[QNum] >= _selqnum
                && IF (
                    MID ( _selquarter, 2, 1 ) = "1",
                    'Table'[QNum] <= _selqnum + 3,
                    'Table'[QNum] <= _selqnum + 9
                )
        )
    )

4. Create a slicer using the quarter field in dimension table

5. Create a matrix visual

yingyinr_2-1655802768948.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi  @arunalle ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a quarters dimenstion table as below(DO NOT create any relationship with the fact tables)

yingyinr_0-1655802517974.png

2. Create a calculated column to get the number in quarter field

QNum = VALUE ( RIGHT ( 'Table'[Quarter], 2 ) & MID ( 'Table'[Quarter], 2, 1 ) )

yingyinr_1-1655802592806.png

3. Create a measure as below to get the sales amount

Measure = 
VAR _selquarter =
    SELECTEDVALUE ( 'Quarters'[Quarter] )
VAR _selqnum =
    CALCULATE (
        MAX ( 'Table'[QNum] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Quarter] = _selquarter )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Sales amount] ),
        FILTER (
            'Table',
            'Table'[QNum] >= _selqnum
                && IF (
                    MID ( _selquarter, 2, 1 ) = "1",
                    'Table'[QNum] <= _selqnum + 3,
                    'Table'[QNum] <= _selqnum + 9
                )
        )
    )

4. Create a slicer using the quarter field in dimension table

5. Create a matrix visual

yingyinr_2-1655802768948.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

@arunalle So, the best way to address this would be to have a Dates table. You would build a relationship to your fact table. In the Dates table you could create a sequential quarter value similar to Sequential: Sequential - Microsoft Power BI Community

 

Then the last 3 quarters is always the current selected quarter minus 3 or 2 depending on how you want it to work.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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