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
sneevand
Frequent Visitor

Each Customer Total Rollup

YearValueMonthValueCustomerNoQty
20191110
2019215
20193220
20201320
2020225
2020312
20201110

 

We want to group by customer, which provide total as below; if the customer dont have value in previous year for a particualr moth or date and  ignore in total and default the value to zero, Measured is preffered choice.

 

Expected Output

CustomerNoYearValueTotalQty
1202012
220205
320200

 

 

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Hi @sneevand ,

 

You can use the following measure for instead:

 

Measure =
SUMX (
    SUMMARIZE (
        'Table',
        'Table'[CustomerNo],
        'Table'[YearValue],
        "Total Qty",
            IF (
                CALCULATE (
                    SUM ( 'Table'[Qty] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
                        'Table'[YearValue]
                            = MAX ( 'Table'[YearValue] ) - 1
                    )
                ) = 0,
                0,
                CALCULATE (
                    SUM ( 'Table'[Qty] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
                        'Table'[YearValue] = MAX ( 'Table'[YearValue] )
                    )
                )
            )
    ),
    [Total Qty]
)

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-deddai1-msft
Community Support
Community Support

Hi @sneevand ,

 

You can use the following measure:

 

Measure =
IF (
    CALCULATE (
        SUM ( 'Table'[Qty] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
            'Table'[YearValue]
                = MAX ( 'Table'[YearValue] ) - 1
        )
    ) = 0,
    0,
    CALCULATE (
        SUM ( 'Table'[Qty] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
            'Table'[YearValue] = MAX ( 'Table'[YearValue] )
        )
    )
)

 

Capture.PNG

 

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

 

Best Regards,

Dedmon Dai

Check the total instead of 17 it shows as  37 ; and it does not work simirally if i join with date dimension; my date dimension dates from min and max date of the customer table.

 

i updated the code to use dates from date dimension,

filter(ALLEXCEPT(Dates,Dates[Date]),Dates[MonthValue]=validmonth && Dates[YearValue]=validyear)

 and did sumx(values(customertable),measure) , but total wont match.

 

Hi @sneevand ,

 

You can use the following measure for instead:

 

Measure =
SUMX (
    SUMMARIZE (
        'Table',
        'Table'[CustomerNo],
        'Table'[YearValue],
        "Total Qty",
            IF (
                CALCULATE (
                    SUM ( 'Table'[Qty] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
                        'Table'[YearValue]
                            = MAX ( 'Table'[YearValue] ) - 1
                    )
                ) = 0,
                0,
                CALCULATE (
                    SUM ( 'Table'[Qty] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[CustomerNo] ),
                        'Table'[YearValue] = MAX ( 'Table'[YearValue] )
                    )
                )
            )
    ),
    [Total Qty]
)

 

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

 

Best Regards,

Dedmon Dai

PhilipTreacy
Super User
Super User

Hi @sneevand 

Sorry I'm not following the logic for your expected output.  You say if the customer dont have value in previous year for a particualr moth or date and  ignore in total and default the value to zero  

So with Customer 1 in 2020 they have values for Jan and Mar,but in 2019 they only have a value for Jan, so why is the 2020 total 12? Shouldn't the Mar 2020 value be treated as 0?

Same thing for Customer 2?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


corrected the data, Customer 3 dont have value for 2019 so it marked as 0 but customer 1,2 are having values in 2019 so need to do roll up for that year selected in filter like 2020, suppose i want 2019 then i will verify with 2018 data and get totals and  so on..

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.