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
Anonymous
Not applicable

Add new column based on current row values, using multiple filters

Hi there

 

I am new to Power BI and I am still learning how to use DAX.

 

I want to add a calculated column which uses multiple filters based on a value taken from the current column. My purpose is to look up current months value and add a column with the last months value for that row (I would like to create the column in red below).

 

ValueIDTypeDateProject NameLast Month DateDates MonthDates LastMonthLast Month Value
0KPI 1Red01/09/2020Project A02/08/20202020092020081
0KPI 2Red01/09/2020Project A02/08/20202020092020082
0KPI 1Red01/09/2020Project B02/08/20202020092020083
0KPI 2Red01/09/2020Project C02/08/20202020092020084
1KPI 1Red10/08/2020Project A11/07/20202020082020070
2KPI 2Red10/08/2020Project A11/07/20202020082020070
3KPI 1Red10/08/2020Project B11/07/20202020082020070
4KPI 2Red10/08/2020Project C11/07/20202020082020070
0Task 1Blue28/08/2020Project A29/07/20202020082020071000
0Task 2Blue28/08/2020Project A29/07/20202020082020072000
0Task 3Blue28/08/2020Project A29/07/20202020082020073000
0Task 4Blue28/08/2020Project A29/07/20202020082020074000
1000Task 1Blue28/07/2020Project A28/06/20202020072020060
2000Task 2Blue28/07/2020Project A28/06/20202020072020060
3000Task 3Blue28/07/2020Project A28/06/20202020072020060
4000Task 4Blue28/07/2020Project A28/06/20202020072020060

 

I have copied the DAX on the link below as it is similar to my problem.

https://community.powerbi.com/t5/Desktop/Add-new-column-with-filters-based-on-current-row-values/m-p...

 

Last Month Value =
VAR LastMonth = 'PBI Risk Project'[Dates.LastMonth]
RETURN
CALCULATE(
SUM('PBI Risk Project'[Value]),
FILTER(ALL('PBI Risk Project'),
'PBI Risk Project'[Dates.Month]=LastMonth ))

 

This does filter my data by the last month but it gives only one total number of the value column for the month on for each row. I need help to filter by Last Month, Project Name and ID. 

 

There is can be multiple IDs of the same name but only one per project per month e.g. Project A only has one KPI 1 for September, one in August and one in July , but there are multiple projects. Is it possible to filter by Last month AND, by Project Name AND by ID for the additional column ?

 

Many thanks in advance for your help

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a calculated column expression that returns your desired result.  FYI that you could also do this as a measure instead.

 

Last Month Value New =
VAR lastmonth = 'PBI Risk Project'[Dates LastMonth]
RETURN
    CALCULATE (
        SUM ( 'PBI Risk Project'[Value] ),
        ALLEXCEPT (
            'PBI Risk Project',
            'PBI Risk Project'[Project Name],
            'PBI Risk Project'[ID]
        ),
        'PBI Risk Project'[Dates Month] = lastmonth
    ) + 0

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Here is a calculated column expression that returns your desired result.  FYI that you could also do this as a measure instead.

 

Last Month Value New =
VAR lastmonth = 'PBI Risk Project'[Dates LastMonth]
RETURN
    CALCULATE (
        SUM ( 'PBI Risk Project'[Value] ),
        ALLEXCEPT (
            'PBI Risk Project',
            'PBI Risk Project'[Project Name],
            'PBI Risk Project'[ID]
        ),
        'PBI Risk Project'[Dates Month] = lastmonth
    ) + 0

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

It worked! Thank you very much for your help 🙂

 

If I use a similar expression in a measure it will work as well or it needs to be written differently?

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.