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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Mr_Indy
Frequent Visitor

Rolling subtraction by quarter

I have the total number (108) and i want to subtract it with the value i have every quarter. (I can have the total number as a Column or as measure.) My problem is that I want to use the "Count by quarter", which is giving me the total amount of items that need to be subtracted. The way the report is builded, i have the same number for every record. What i want to have at the end is
Total = 108

Q4 2022 = 7
New Total = 108-7 = 101
Q1 2023 = 17
New total = 101-17= 84

etc
Any idea how can i do it with DAX or some other method?

Thank you in advance

 

Mr_Indy_0-1670849980611.png

 

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

Hi @Mr_Indy ,

 

We need a column like [Index] or [YearQuarter] to sort your [QT] column. Here I suggest you to create a DimDate table by dax.

DimDate = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2022, 01, 01 ), DATE ( 2023, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "Quarter", QUARTER ( [Date] ),
    "QT",
        "Q" & ""
            & FORMAT ( [Date], "Q YYYY" ),
    "QY",
        YEAR ( [Date] ) * 100
            + QUARTER ( [Date] )
)

Relationship:

RicoZhou_1-1670899039852.png

Then you can try this code to create a calcualted column.

Rolling subtraction by quarter =
VAR _STEP1 =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[Burndown],
        'Table'[Count by quarter],
        'Table'[QT],
        "QY", CALCULATE ( MAX ( DimDate[QY] ) )
    )
VAR _STEP2 =
    ADDCOLUMNS (
        _STEP1,
        "Rolling subtraction by quarter",
            108
                - SUMX ( FILTER ( _STEP1, [QY] <= EARLIER ( [QY] ) ), [Count by quarter] )
    )
RETURN
    SUMX (
        FILTER ( _STEP2, [QT] = EARLIER ( 'Table'[QT] ) ),
        [Rolling subtraction by quarter]
    )

Result is as below.

RicoZhou_0-1670898838970.png

 

Best Regards,
Rico Zhou

 

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-rzhou-msft
Community Support
Community Support

Hi @Mr_Indy ,

 

We need a column like [Index] or [YearQuarter] to sort your [QT] column. Here I suggest you to create a DimDate table by dax.

DimDate = 
ADDCOLUMNS (
    CALENDAR ( DATE ( 2022, 01, 01 ), DATE ( 2023, 12, 31 ) ),
    "Year", YEAR ( [Date] ),
    "Month", MONTH ( [Date] ),
    "Quarter", QUARTER ( [Date] ),
    "QT",
        "Q" & ""
            & FORMAT ( [Date], "Q YYYY" ),
    "QY",
        YEAR ( [Date] ) * 100
            + QUARTER ( [Date] )
)

Relationship:

RicoZhou_1-1670899039852.png

Then you can try this code to create a calcualted column.

Rolling subtraction by quarter =
VAR _STEP1 =
    SUMMARIZE (
        ALL ( 'Table' ),
        'Table'[Burndown],
        'Table'[Count by quarter],
        'Table'[QT],
        "QY", CALCULATE ( MAX ( DimDate[QY] ) )
    )
VAR _STEP2 =
    ADDCOLUMNS (
        _STEP1,
        "Rolling subtraction by quarter",
            108
                - SUMX ( FILTER ( _STEP1, [QY] <= EARLIER ( [QY] ) ), [Count by quarter] )
    )
RETURN
    SUMX (
        FILTER ( _STEP2, [QT] = EARLIER ( 'Table'[QT] ) ),
        [Rolling subtraction by quarter]
    )

Result is as below.

RicoZhou_0-1670898838970.png

 

Best Regards,
Rico Zhou

 

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

Thank you Rico, it worked like a charm!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.