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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Summing multiple columns based on dynamic filter

Lets say I have the following dataset:

 

ProjectJanuaryFebruaryMarchAprilMayJuneYTD
A1223155234512?
B53432591010?

 

I would like to add a YTD column that adds up all the months data up to the date selected via a slicer. For example, if April was selected on the slicer, then the YTD columns for Project A would be (12 + 23 + 155 + 23 = 213). How would I go about doing this? 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Have you solved this problem? If not, you may take steps below for reference.

1. For more convenient operation, you can transpose the table first.

v-xiaotang_0-1620294390251.png

Hit Use First Row as Headers, then

v-xiaotang_1-1620294390255.png

2. Create a calendar table

v-xiaotang_2-1620294390258.png

 

Calendar Table = SUMMARIZE('Table','Table'[Project])

 

Keep them disconnected

v-xiaotang_3-1620294390259.png

3. Create the three measures

 

sel month = SWITCH (
    MAX('Table'[Project]),
    "January",1,
    "February",2,
    "March",3,
    "April",4,
    "May",5,
    "June",6
)
YTD_A =
VAR slicer_month =
    SWITCH (
        MAX ( 'Calendar Table'[Project] ),
        "January", 1,
        "February", 2,
        "March", 3,
        "April", 4,
        "May", 5,
        "June", 6
    )
VAR total =
    CALCULATE (
        SUM ( 'Table'[A] ),
        KEEPFILTERS ( FILTER ( ALL ( 'Table' ), 'Table'[sel month] <= slicer_month ) )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Project] ), SELECTEDVALUE ( 'Table'[A] ), total )
YTD_B =
VAR slicer_month =
    SWITCH (
        MAX ( 'Calendar Table'[Project] ),
        "January", 1,
        "February", 2,
        "March", 3,
        "April", 4,
        "May", 5,
        "June", 6
    )
VAR total =
    CALCULATE (
        SUM ( 'Table'[B] ),
        KEEPFILTERS ( FILTER ( ALL ( 'Table' ), 'Table'[sel month] <= slicer_month ) )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Project] ), SELECTEDVALUE ( 'Table'[B] ), total )

 

4.then,

v-xiaotang_4-1620294390261.png

 

v-xiaotang_5-1620294390264.png

Result:

v-xiaotang_6-1620294390267.png

v-xiaotang_7-1620294390270.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Have you solved this problem? If not, you may take steps below for reference.

1. For more convenient operation, you can transpose the table first.

v-xiaotang_0-1620294390251.png

Hit Use First Row as Headers, then

v-xiaotang_1-1620294390255.png

2. Create a calendar table

v-xiaotang_2-1620294390258.png

 

Calendar Table = SUMMARIZE('Table','Table'[Project])

 

Keep them disconnected

v-xiaotang_3-1620294390259.png

3. Create the three measures

 

sel month = SWITCH (
    MAX('Table'[Project]),
    "January",1,
    "February",2,
    "March",3,
    "April",4,
    "May",5,
    "June",6
)
YTD_A =
VAR slicer_month =
    SWITCH (
        MAX ( 'Calendar Table'[Project] ),
        "January", 1,
        "February", 2,
        "March", 3,
        "April", 4,
        "May", 5,
        "June", 6
    )
VAR total =
    CALCULATE (
        SUM ( 'Table'[A] ),
        KEEPFILTERS ( FILTER ( ALL ( 'Table' ), 'Table'[sel month] <= slicer_month ) )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Project] ), SELECTEDVALUE ( 'Table'[A] ), total )
YTD_B =
VAR slicer_month =
    SWITCH (
        MAX ( 'Calendar Table'[Project] ),
        "January", 1,
        "February", 2,
        "March", 3,
        "April", 4,
        "May", 5,
        "June", 6
    )
VAR total =
    CALCULATE (
        SUM ( 'Table'[B] ),
        KEEPFILTERS ( FILTER ( ALL ( 'Table' ), 'Table'[sel month] <= slicer_month ) )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[Project] ), SELECTEDVALUE ( 'Table'[B] ), total )

 

4.then,

v-xiaotang_4-1620294390261.png

 

v-xiaotang_5-1620294390264.png

Result:

v-xiaotang_6-1620294390267.png

v-xiaotang_7-1620294390270.png

Hope this helps.

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

hi, @Anonymous 

I am not sure how your actual data model looks like, but I suggest having the fact table's structure like below.

You can easily transform the table structure in Power Query Editor.

 

And also, a separate slicer table is needed in this case.

 

All measures are in the sample pbix file. (Link down below).

 

Picture9.png

 

Values Total YTD =
VAR slicerdate =
MAX ( Slicer[Date] )
RETURN
CALCULATE (
TOTALYTD ( [Values Total], 'Calendar'[Date] ),
KEEPFILTERS ( FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= slicerdate ) )
)
 
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.