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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Zaibass81
Helper I
Helper I

sum every nth and insert blank

Hi
Looking for a solution on the example below, basically on the right side is the desired output was depending on type A or B adding monthly qty's then inserting blank and continues summing.
Any help more than appreciated.

 

Example.JPG

 

 

 

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

Hi @Zaibass81 ,

 

We can create a measure as below to work on it.

Measure = 
VAR ty =
    MAX ( data[Type] )
VAR mon =
    MONTH ( MAX ( 'data'[DATE] ) )
VAR pre = mon - 1
VAR next = mon + 1
VAR m2 =
    MOD ( mon, 2 )
RETURN
    IF (
        ty = "A"
            && m2 = 1,
        SUM ( data[value] )
            + CALCULATE (
                SUM ( data[value] ),
                FILTER ( ALLEXCEPT ( data, data[Category] ), MONTH ( 'data'[DATE] ) = next )
            ),
        IF (
            ty = "B"
                && m2 = 0,
            SUM ( data[value] )
                + CALCULATE (
                    SUM ( data[value] ),
                    FILTER ( ALLEXCEPT ( data, data[Category] ), MONTH ( 'data'[DATE] ) = pre )
                )
        )
    )

Capture.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

6 REPLIES 6
v-frfei-msft
Community Support
Community Support

Hi @Zaibass81 ,

 

We can create a measure as below to work on it.

Measure = 
VAR ty =
    MAX ( data[Type] )
VAR mon =
    MONTH ( MAX ( 'data'[DATE] ) )
VAR pre = mon - 1
VAR next = mon + 1
VAR m2 =
    MOD ( mon, 2 )
RETURN
    IF (
        ty = "A"
            && m2 = 1,
        SUM ( data[value] )
            + CALCULATE (
                SUM ( data[value] ),
                FILTER ( ALLEXCEPT ( data, data[Category] ), MONTH ( 'data'[DATE] ) = next )
            ),
        IF (
            ty = "B"
                && m2 = 0,
            SUM ( data[value] )
                + CALCULATE (
                    SUM ( data[value] ),
                    FILTER ( ALLEXCEPT ( data, data[Category] ), MONTH ( 'data'[DATE] ) = pre )
                )
        )
    )

Capture.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi,
just another quick question, what i need to change in the measure below, to sum in 3 monthly buckets i.e. category A Jan+Feb+Mar (=6) instead of what it's doing at the moment every 2 monthly buckets (Jan+feb =3)

 

Thanks in advance

 

That's exacly what i am looking for, however, i was looking to do it with power query, or DAX , not with BI, as i am not using it.

 

Thanks,

 

T.

@Zaibass81 Power BI is a product that uses Power Query to extract, transform, and load data, then DAX to analyze the data. So when you say you want to do with with DAX or Power Query but not BI, that doesn't make sense. 

 

If you mean you want to do it in Excel using Power Query or DAX (via Power Pivot) then unless the solution provided uses some newer DAX functions (those from 2018 or later), it will work fine there too.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Ok, perhaps my english.. however, what i ment is that i am looking for a solution in M language which is uesed by power query.

 

Rgds,

 

T

edhans
Super User
Super User

Can you provide actual data in a table or linked Excel file from OneDrive, and explain what it is you are wanting? At a glance, I cannot tell what the yellow and red things are doing. Provide explicit details on how to get from the left side to the right side.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.

Top Solution Authors