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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Petanek333
Helper III
Helper III

Creating dynamic groups based on a measure

Hi, I would like to create groups of data based on a measure. To be honest, I don't even know if it is possible.

I have a table like this:

Petanek333_0-1666163518586.png

It basicaly says that in a week number 33 there were 57 units of product A (inventory) and 3 units were sold so the client has 19 weeks remaining of stock at this rate of sales. 

I have then created a calculated column with groups like Too much stock (over 18 weeks of sales), Perfect (between 8 and 18 weeks) and Running out (less than 8 weeks). 

I need to visualize it like this 

Petanek333_1-1666165241537.png

But a new request came up. They want to calculate not only the weeks remaining (inventory divided by sales) but also a "months remaining" or better put 4-week periods remaining. So I created a measure calculating the most recent week selected inventory divided by all the selected months' sales. For example if I select weeks 32, 33, 34 and 35, the formula is inventory of week 35 / (sales of weeks 32+33+34+35). 

 

Max Week Inventory =
CALCULATE (
    SUM ( 'Dummy Data'[Inventory Quantity] ),
    FILTER (
        ALL ( 'Dummy Data'[Year-Week] ),
        'Dummy Data'[Year-Week] = MAX ( 'Dummy Data'[Year-Week] )
    )
)
Weeks Remaining NEW =
DIVIDE (
    [Max Week Inventory],
    SUM ( 'Dummy Data'[Sales Quantity] ),
    "No sales"
)

 

But as the Groups are static (calculated column for each row of data) I would like to create a bar chart like the one above, but the groups Running out, Perfect and Too much should be dynamic.

So if I select 4 weeks like this:

Petanek333_2-1666166198125.png

Then the bar chart should only show a Running Out bar worth 14 389 EUR because all the weeks remaining values are below 8. 

I struggle with - connecting a table like this to a measure.

Petanek333_3-1666166351309.png

And since I don't know how to create a relationship between the table with categories and the measure, I can't try to see if it can be displayed in a graph like this. Can you help me with this? 

 

Sample file attached:

Sample file 

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Petanek333 

 

You can try this measure 

Measure = 
VAR _table = SUMMARIZE('Dummy Data','Dummy Data'[ID],"week_remaining_new",[Weeks Remaining NEW],"max_week_inventory_value",[Max Week Inventory Value])
RETURN
SWITCH(SELECTEDVALUE('Stock Category'[Type]),
    "N/A",SUMX(FILTER(_table,[week_remaining_new]<=0),[max_week_inventory_value]),
    "Running Out",SUMX(FILTER(_table,[week_remaining_new]>0 && [week_remaining_new]<=8),[max_week_inventory_value]),
    "Perfect",SUMX(FILTER(_table,[week_remaining_new]>8 && [week_remaining_new]<=18),[max_week_inventory_value]),
    "Too much",SUMX(FILTER(_table,[week_remaining_new]>18),[max_week_inventory_value])
)

vjingzhang_0-1666246004410.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @Petanek333 

 

You can try this measure 

Measure = 
VAR _table = SUMMARIZE('Dummy Data','Dummy Data'[ID],"week_remaining_new",[Weeks Remaining NEW],"max_week_inventory_value",[Max Week Inventory Value])
RETURN
SWITCH(SELECTEDVALUE('Stock Category'[Type]),
    "N/A",SUMX(FILTER(_table,[week_remaining_new]<=0),[max_week_inventory_value]),
    "Running Out",SUMX(FILTER(_table,[week_remaining_new]>0 && [week_remaining_new]<=8),[max_week_inventory_value]),
    "Perfect",SUMX(FILTER(_table,[week_remaining_new]>8 && [week_remaining_new]<=18),[max_week_inventory_value]),
    "Too much",SUMX(FILTER(_table,[week_remaining_new]>18),[max_week_inventory_value])
)

vjingzhang_0-1666246004410.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Hi @v-jingzhang , the measure works with this visual as expected. However, if I understand it right, those categories (Running Out, ...) are only created in a virtual table or in a measure, but is there any way to link to them in another visual?

Let's say I want to drillthough Running Out Category in this setup:

Petanek333_0-1666361537437.png

I can drillthrough for example Product C in Running Out category, but if I want to drillthrough more than one selection, I can use a trick with a card visual. 

If I click Product C and Product D holding Ctrl key, I basicaly selected the whole Running Out category and if I right-click the card visual and drillthrough, I successfully drillthrough to 10k. 

Petanek333_1-1666361957972.png

 

But if I click the Running Out category as a whole and then want to drillthrough via card visual, I get 14 381 EUR (thats everything for given week) and not only the Running Out category.

Petanek333_2-1666362006275.png

Petanek333_3-1666362030605.png

 

 

I think that happens because the Running Out category is only defined in that measure so my question is, is there any other way so that the drilling through would work?

 

Sample data 

Thank you very much @v-jingzhang , this is exactly what I was looking for.

Petanek333
Helper III
Helper III

I figured I could use a measure like this to create dynamic categories:

Category Measure =
SWITCH (
    TRUE (),
    [Weeks Remaining NEW] <= 0, "N/A",
    [Weeks Remaining NEW] <= 8, "Running Out",
    [Weeks Remaining NEW] <= 18, "Perfect",
    "Too much"
)

But since I cannot use a measure as a legend in a chart, I don't have a solution to my problem

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.