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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
AhmadJamil
Frequent Visitor

Summarize values by Category less or equal to Slicer value

I have 3 slicers on my following data (Category1, Category2, Period) and I need a Card showing the Total of (Value) based on slicers, which is easy. The part where I need the help is to show a bar chart with Period on X-Axis and Values on Y-Axis. This Chart should respond to Category1 and Category 2 normally, nevertheless, all Periods lower or equal to Period Slicer should be shown on the X-Axis. e.g. if Period 2023 (2) is selected in the slicer it should show two bars providing total of (Value) for Period 2023 (1) and Period 2023 (2).

Category 1Category 2Period IDPeriod  Value
P1M112023 (1)20
P1M212023 (1)30
P1M312023 (1)50
P1M112023 (1)41
P2M212023 (1)52
P2M412023 (1)36
P2M112023 (1)60
P2M112023 (1)47
P2M312023 (1)59
P1M122023 (2)83
P1M222023 (2)70
P1M322023 (2)82
P1M122023 (2)106
P2M222023 (2)93
P2M422023 (2)105
P2M122023 (2)129
P2M122023 (2)116
P2M322023 (2)128
P1M132023 (3)152
P1M232023 (3)139
P1M332023 (3)151
P1M132023 (3)175
P2M232023 (3)162
P2M432023 (3)174
P2M132023 (3)198
P2M132023 (3)185
P2M332023 (3)197

 

So, assuming I have selected Period "2023 (2)", it should show me following chart, which should be responsive to Category1 and Category 2 as well:

AhmadJamil_0-1700608241481.png

 

Please let me know if I need to make a measure or a calculated table (which I doubt because Calculated table will not respond to my slicer).
Thanking you in anticipation.

Ahmad

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@AhmadJamil,

 

Try this solution. Create a calculated table Periods:

 

Periods = SUMMARIZE ( FactTable, FactTable[Period], FactTable[Period ID] )

 

This table has no relationship with FactTable. Create measure:

 

Cumulative Total = 
VAR vPeriodSelection =
    SELECTEDVALUE ( Periods[Period ID] )
VAR vResult =
    IF (
        MAX ( FactTable[Period ID] ) <= vPeriodSelection,
        CALCULATE (
            SUM ( FactTable[Value] ),
            FILTER (
                ALLSELECTED ( FactTable ),
                FactTable[Period ID] <= MAX ( FactTable[Period ID] )
            )
        )
    )
RETURN
    vResult

 

Create slicer using Periods[Period]. Create visual using FactTable[Period] and the measure above.

 

DataInsights_0-1700772913507.png

This technique is explained in the article below.

 

https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/ 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
gmsamborn
Super User
Super User

Hi @AhmadJamil , @DataInsights 

 

I curious why you didn't set your slicer to Period ID, in Slicer Settings set to Less than or equal to, and rename the slicer from Period ID to Period.

 

Also, I didn't see anything in the requirements about displaying cumulative totals instead to period totals.

 

Sorry if I'm way off base here.

 

Mine - no measures.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

@gmsamborn,

 

Using a Before slicer is a good approach, and one that I typically use. It gives you more flexibility with date calculations, and it's simpler for users to set one date and have the entire report calculate per that date. The Periods table would actually be replaced by a robust date table in a production model.

 

Check the requirement "all periods lower or equal to period slicer". This could be achieved with a YTD calculation, which is likely what would happen in a production model so years aren't combined.

 

Thanks for your comments!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @DataInsights 

 

I'm guessing where that is a part of "all Periods lower or equal to Period Slicer should be shown on the X-Axis."

Also, "show a bar chart with Period on X-Axis and Values on Y-Axis."

 

Regardless, if a date table isn't being used already , it should be.  Then functions like DATESYTD and TOTALYTD would be usable.

 



Proud to be a Super User!

daxformatter.com makes life EASIER!
DataInsights
Super User
Super User

@AhmadJamil,

 

Try this solution. Create a calculated table Periods:

 

Periods = SUMMARIZE ( FactTable, FactTable[Period], FactTable[Period ID] )

 

This table has no relationship with FactTable. Create measure:

 

Cumulative Total = 
VAR vPeriodSelection =
    SELECTEDVALUE ( Periods[Period ID] )
VAR vResult =
    IF (
        MAX ( FactTable[Period ID] ) <= vPeriodSelection,
        CALCULATE (
            SUM ( FactTable[Value] ),
            FILTER (
                ALLSELECTED ( FactTable ),
                FactTable[Period ID] <= MAX ( FactTable[Period ID] )
            )
        )
    )
RETURN
    vResult

 

Create slicer using Periods[Period]. Create visual using FactTable[Period] and the measure above.

 

DataInsights_0-1700772913507.png

This technique is explained in the article below.

 

https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/ 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi DataInsights, 
Thank you so very much, yes I was looking for somehting like this. I have apply it to a large complex solution where the same Filter is also being used to filter other visuals that are based on fact table. Do you have any suggestion to have a single filter not based on Periods table.



Regards,
Ahmad

@AhmadJamil,

 

Do you have a mockup of what you are trying to achieve?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors