cancel
Showing results for 
Search instead for 
Did you mean: 
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
Microsoft

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
Microsoft

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
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors