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
VuongLM93
Helper III
Helper III

Sum history sales based on current filter context

Dear All

I have a sales table monthly volume with 2 salesperson : A, B

I have 2 customer 1, customer 2 . After 2019 to 2020 , the customers are allocated from A to B .

Now in a matrix visual -> I want to see the sales of customer of "B" in current month (for example 7 .2020 ) , but also sum their total volume in 2019 (which was allocated by A thus cannot show for B ).

 

 SalesPerson20202019
  Month77
Current on my report (wrong outcome) A030
  B70

0  ***

My desired outcome A030
  B7030 ***

 

 

Customer CodeSalesPersonMonthYearSales
Customer 1A7201910
Customer 2A7201920
Customer 1B7202030
Customer 2B7202040
1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @VuongLM93 ,

You can create a calculated table first:

Test =
SUMMARIZE ( 'Table', 'Table'[Year], 'Table'[Month] )

Create this measure:

Measure =
SWITCH (
    SELECTEDVALUE ( 'Table'[Sales Person] ),
    "A",
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Month] = SELECTEDVALUE ( 'Test'[Month] )
                    && 'Table'[Year] = SELECTEDVALUE ( 'Test'[Year] )
                    && 'Table'[Sales Person] = "A"
            )
        ),
    "B",
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Month] = SELECTEDVALUE ( 'Test'[Month] )
                    && 'Table'[Year] = SELECTEDVALUE ( 'Test'[Year] )
            )
        )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

4 REPLIES 4
VuongLM93
Helper III
Helper III

@v-yingjl  Unfortunately - I cannot create a table ( because the dataset is not mine. I am connecting to live dataset

Therefore I can only create measures,

 

v-yingjl
Community Support
Community Support

Hi @VuongLM93 ,

You can create a calculated table first:

Test =
SUMMARIZE ( 'Table', 'Table'[Year], 'Table'[Month] )

Create this measure:

Measure =
SWITCH (
    SELECTEDVALUE ( 'Table'[Sales Person] ),
    "A",
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Month] = SELECTEDVALUE ( 'Test'[Month] )
                    && 'Table'[Year] = SELECTEDVALUE ( 'Test'[Year] )
                    && 'Table'[Sales Person] = "A"
            )
        ),
    "B",
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                'Table'[Month] = SELECTEDVALUE ( 'Test'[Month] )
                    && 'Table'[Year] = SELECTEDVALUE ( 'Test'[Year] )
            )
        )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Yingjie Li

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

@VuongLM93 , better create a separate year table and join it with the year of your table

and try a measure like

 

Cumm Sales = CALCULATE(SUM(Sales[Sales]),filter(all(Year[Year]),Year[Year] <=max(Year[Year])))

Cumm Sales = CALCULATE(SUM(Sales[Sales]),filter(allselected(Year[Year]),Year[Year] <=max(Year[Year])))

 

or with your current table

Cumm Sales = CALCULATE(SUM(Sales[Sales ]),filter(all(table[Year]),table[Year] <=max(table[Year])))

 

Why in your formula use filter by year

Does it work if i need to show different month?

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.