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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
bsas
Post Patron
Post Patron

calculate revenue per "dynamic" category based on period slicer selection

Hi All,


I'm struggling with approach to calculate revenue per "dynamic" category which is based on period slicer selection. In case month granularity appears on chart show revenue per category monthly, if quarter - show revenue (sum of all revenue in quarter) per category, if year - show revenue (sum of all revenue in year) per category.
Have fact table with monthly granularity and relation to date table on date filelds.
Is it even possible to calculate such logic in Power BI?
Sample of data

AccountDate Amount 
11111/1/2022 $       100
11112/1/2022 $       300
11113/1/2022 $       200
11114/1/2022 $       100
11115/1/2022 $       600
11116/1/2022 $       200
11117/1/2022 $       300
22221/1/2022 $       600
22222/1/2022 $       400
22223/1/2022 $       500
22224/1/2022 $       400
22225/1/2022 $       500
22226/1/2022 $       600
22227/1/2022 $       700
22228/1/2022 $       600

categoty values

smallmidlarge
<= 300> 300 <= 1000> 1000


Expected result
monthly aggregation

bsas_0-1675358823925.png
quarter aggregation

bsas_1-1675358856865.png

in case of year aggregation

bsas_2-1675358933659.png

 




2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@bsas , You need to consider Dynamic Segmentation, but buckets will static

 

Dynamic Segmentation Bucketing Binning
https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1...


Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

Hi @bsas ,

 

I think you want to show two legends [Category] and [Amount] in Stacked column chart in Power BI. Currently, Power BI doesn't support us to add two legends directly. Here I suggest you to try Small multiples function.

Data model:

RicoZhou_0-1675409752029.png

Measure:

Amount by Category =
SWITCH (
    SELECTEDVALUE ( Category[Category] ),
    "Small",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) <= 300,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        ),
    "Mid",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) <= 1000
                && CALCULATE ( SUM ( 'Table'[ Amount ] ) ) > 300,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        ),
    "Large",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) > 1000,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        )
)

Result is as below.

RicoZhou_1-1675409768098.png

RicoZhou_2-1675409778620.png

RicoZhou_3-1675409786722.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

3 REPLIES 3
Anonymous
Not applicable

Hi @bsas ,

 

I think you want to show two legends [Category] and [Amount] in Stacked column chart in Power BI. Currently, Power BI doesn't support us to add two legends directly. Here I suggest you to try Small multiples function.

Data model:

RicoZhou_0-1675409752029.png

Measure:

Amount by Category =
SWITCH (
    SELECTEDVALUE ( Category[Category] ),
    "Small",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) <= 300,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        ),
    "Mid",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) <= 1000
                && CALCULATE ( SUM ( 'Table'[ Amount ] ) ) > 300,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        ),
    "Large",
        IF (
            CALCULATE ( SUM ( 'Table'[ Amount ] ) ) > 1000,
            CALCULATE ( SUM ( 'Table'[ Amount ] ) )
        )
)

Result is as below.

RicoZhou_1-1675409768098.png

RicoZhou_2-1675409778620.png

RicoZhou_3-1675409786722.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.

 

amitchandak
Super User
Super User

@bsas , You need to consider Dynamic Segmentation, but buckets will static

 

Dynamic Segmentation Bucketing Binning
https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1...


Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you @amitchandak ! I was moving in similar direction but your article inspired on new idea. At the end for my case I created separate table with ID and Label fields then created measure using switch and sumx. 

____RevenueCustomerSizeChart =

SWITCH(
    SELECTEDVALUE(CustomerSize[SizeID]),
    1, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] >= 20000000), [____RevenueComposite]),
    2, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] >= 10000000 && [____RevenueComposite] < 20000000), [____RevenueComposite]),
    3, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] >= 5000000 && [____RevenueComposite] < 10000000), [____RevenueComposite]),
    4, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] >= 1000000 && [____RevenueComposite] < 5000000), [____RevenueComposite]),
    5, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] >= 500000 && [____RevenueComposite] < 1000000), [____RevenueComposite]),
    6, SUMX( FILTER( VALUES( Data[AccountID]),
                [____RevenueComposite] > 0 && [____RevenueComposite] < 500000), [____RevenueComposite])
)

 



Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.