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 August 31st. Request your voucher.

Reply
ryanxngo
New Member

FILTER using column values instead of a scalar value

I am trying to create a cumulative sum measure using the following formula:

Cumulative_Cash =
VAR CurrentRowDate = MAX(FactSales[CalendarDate])
VAR SelectedGrains = VALUES(FactSales[Grain])
RETURN CALCULATE(
    SUM(FactSales[Total_Cash]),
    FactSales[Grain] = SelectedGrains,
    FILTER(
        ALL(FactSales),
        FactSales[CalendarDate] <= CurrentRowDate
    )
)

Within the FILTER function, I have an additional condition for Grain:
FactSales[Grain] = SelectedGrains
If it is only one selection, it works but if I select two or more grains it gives error: A table of multiple values was supplied where a single value was expected.

Is there anyway to filter the FactSales[Grain] column to the values selected in the SelectedGrains table variable?



 

1 ACCEPTED SOLUTION

hi @ryanxngo ,

 

try like:

1) add a calculated column like:

 

MonthNO = FORMAT([Date], "YYYYMM")

 

 2) plot a table visual with month column and a measure like:

 

C_Cash = 
SUMX(
    FILTER(
        ALLSELECTED(data), 
        data[MonthNO]<=MAX(data[MonthNO])
    ),
    data[Cash]
)

 

or 

 

C_Cash2 = 
CALCULATE(
    SUM(data[Cash]),
    ALLSELECTED(data), 
    data[MonthNO]<=MAX(data[MonthNO])
)

 

 

it worked like:

FreemanZ_0-1699498451058.pngFreemanZ_1-1699498463344.png

 

View solution in original post

3 REPLIES 3
ryanxngo
New Member

Hi ValtteriN,
Thank you so much, I thought this had worked for me but seems like there's one more issue:
I have a month columns based on Date so if I use the Month column the cumulative sum doesn't work as expected

ryanxngo_1-1699465517705.png

 

Here is my dataset:

ryanxngo_2-1699465560573.png

The formula that I used:

C_Cash =
VAR CurrentRowDate = MAX(FactSales[Date])
RETURN
CALCULATE(
    SUM(FactSales[Total_Cash]),      
        ALL(FactSales[Date]),
        FactSales[Date] <= CurrentRowDate
    )



I hope you can help me with this as well, thanks

hi @ryanxngo ,

 

try like:

1) add a calculated column like:

 

MonthNO = FORMAT([Date], "YYYYMM")

 

 2) plot a table visual with month column and a measure like:

 

C_Cash = 
SUMX(
    FILTER(
        ALLSELECTED(data), 
        data[MonthNO]<=MAX(data[MonthNO])
    ),
    data[Cash]
)

 

or 

 

C_Cash2 = 
CALCULATE(
    SUM(data[Cash]),
    ALLSELECTED(data), 
    data[MonthNO]<=MAX(data[MonthNO])
)

 

 

it worked like:

FreemanZ_0-1699498451058.pngFreemanZ_1-1699498463344.png

 

ValtteriN
Super User
Super User

Hi,

Here is how to do this:

Data:

ValtteriN_0-1699461168993.png

Dax:

Cumulative_Cash =
VAR CurrentRowDate = MAX(FactSales[Date])
RETURN
CALCULATE(
    SUM(FactSales[Total_Cash]),      
        ALL(FactSales[Date]),
        FactSales[Date] <= CurrentRowDate
    )

End result:
ValtteriN_1-1699461272460.png

The calculation seems to work as expected considering the test data.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





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

Proud to be a Super User!




Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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