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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
scott_bab
Frequent Visitor

Calculate sales measure

I have an interesting scenario that I have not been able to crack thus far.

 

I have a slicer where I can select a particular store, and I want to be able to view the department sales for the selected store, in addition to the store's district (1 level higher) and division (2 levels higher).

 

Predictably, I have been able to do this for the store. However, I am getting the overall district & division totals displaying in each department line. Any ideas on how to fix this?

 

Below is how the data is set up, with the results I would expect below that.
Capture1.JPG

 

 

 

 

 

 

 

 

 

Capture2.JPG

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@scott_bab 

 

Hi, try with this measure:

 

Measure =
VAR _District =
    SELECTEDVALUE ( Sales[District] )
VAR _Division =
    SELECTEDVALUE ( Sales[Division] )
VAR _Context =
    SELECTEDVALUE ( Context[Context Name] )
RETURN
    SWITCH (
        _Context;
        "Store"; SUM ( Sales[2018 Sales] );
        "District"; CALCULATE (
            SUM ( Sales[2018 Sales] );
            KEEPFILTERS ( VALUES ( Sales[Department] ) );
            FILTER ( ALL ( 'Sales' ); Sales[District] = _District )
        );
        "Division"; CALCULATE (
            SUM ( Sales[2018 Sales] );
            KEEPFILTERS ( VALUES ( Sales[Department] ) );
            FILTER ( ALL ( 'Sales' ); Sales[Division] = _Division )
        )
    )

If doesn't work replace ; with ,

 

Maybe need to optimize code but i think will work.

 

img2.png

 

PD. I forgot to tell you

 

I create a disconnected table with a column named "Context  with this 3 rows : "Store", "District" and Division" and insert it in Columns section in Matrix)

 

Regards

 

Victor

 




Lima - Peru

View solution in original post

3 REPLIES 3
Vvelarde
Community Champion
Community Champion

@scott_bab 

 

Hi, try with this measure:

 

Measure =
VAR _District =
    SELECTEDVALUE ( Sales[District] )
VAR _Division =
    SELECTEDVALUE ( Sales[Division] )
VAR _Context =
    SELECTEDVALUE ( Context[Context Name] )
RETURN
    SWITCH (
        _Context;
        "Store"; SUM ( Sales[2018 Sales] );
        "District"; CALCULATE (
            SUM ( Sales[2018 Sales] );
            KEEPFILTERS ( VALUES ( Sales[Department] ) );
            FILTER ( ALL ( 'Sales' ); Sales[District] = _District )
        );
        "Division"; CALCULATE (
            SUM ( Sales[2018 Sales] );
            KEEPFILTERS ( VALUES ( Sales[Department] ) );
            FILTER ( ALL ( 'Sales' ); Sales[Division] = _Division )
        )
    )

If doesn't work replace ; with ,

 

Maybe need to optimize code but i think will work.

 

img2.png

 

PD. I forgot to tell you

 

I create a disconnected table with a column named "Context  with this 3 rows : "Store", "District" and Division" and insert it in Columns section in Matrix)

 

Regards

 

Victor

 




Lima - Peru

Thanks @Vvelarde . I'm running into some issues with the Context table - it doesn't seem to like that there is not a relationship between that and my Sales table.

@scott_bab 

 

Hi, the error message is before you drag the measure into Values Section in Matrix. After you put the measure in values you shouldn't see the issue.

 

If you still having the problem let me know to upload a demo file

 

Regards

 

Victor

 

 

 

 

 

 

 

 

 




Lima - Peru

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.