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
jimhick47
New Member

DAX measure that ignores specific row filter

Hi

 

I'm trying to put together some Power BI reports for the company I work in.  I'm only a beginner with BI so I'm struggling with one thing which I'm not even sure is possible.  The data we're using for the reports comes from a SSAS server and because there are millions of rows importing it isn't really an option due to the refresh times so we're having to use a live connection.  Because of this I'm having to use DAX measures to do anything with the data to display the info we need.  Two of the tables in the data are set out similar to below:

 

Table 1:

TaskIdentifierAspect ID
2023-11
2023-12
2023-23
2023-24
2023-35
2023-36

 

Table 2:

Aspect IDTypeValue
1Pages500
2TypeHorror
3Pages250
4TypeSci-Fi
5Pages300
6TypeDrama

 

What I'm trying to get is a matrix visualisation with the 'Type' values as the first row group and the TaskIdentifier as the second (like below):

 

Pages

Horror

     2023-1                               500

Sci-Fi

     2023-2                               250

Drama

     2023-3                               300

 

Basically I just want the page values to summarise based on the TaskIdentifier and ignore the Type grouping completely.  I've got my visualisation set up like below but I can't quite get the DAX right.  Either it shows the total pages for all tasks combined or is just blank. 

jimhick47_1-1698699408441.png

 

I would be extremely grateful for any suggestions anyone might have as I've been stuck on this for days now.  I can't post the data unfortunately as it's confidential but if you need me to clarify anything then please just ask.

 

Many thanks

1 ACCEPTED SOLUTION

@jimhick47,

Though my head isn't fresh at all, I've composed such a measure, which seems to work except for the grand total. I presume this measure will be very slow with a large dataset. Can you give it a try?

barritown_0-1698875920269.png

Pages = 
VAR CurrentID = MAX ( Tbl2[Aspect ID] )
VAR CurrentVal = MAX ( Tbl2[Value] )
VAR LookupID = IF ( ISEVEN ( CurrentID ), CurrentID - 1, CurrentID + 1 )
VAR Res = LOOKUPVALUE ( Tbl2[Value], Tbl2[Aspect ID], LookupID )
VAR AffectedIDs = SELECTCOLUMNS ( FILTER ( ALL ( Tbl2 ), Tbl2[Value] = CurrentVal ), "ID", [Aspect ID] ) 
VAR CalculatedIDs = SELECTCOLUMNS ( ADDCOLUMNS ( AffectedIDs, "ID Values", IF ( ISEVEN ( [ID] ), [ID] - 1, [ID] + 1 ) ), "ID", [ID Values] )
VAR CalculatedValues = SELECTCOLUMNS ( FILTER ( ALL ( Tbl2 ), [Aspect ID] in CalculatedIDs ), "Val", [Value] )
VAR AltRes = SUMX ( CalculatedValues, INT ( [Val] ) )
RETURN IF ( ISFILTERED ( Tbl1[TaskIdentifier] ), Res, AltRes )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

5 REPLIES 5
barritown
Super User
Super User

Hi @jimhick47,

You can try something like this:

barritown_0-1698747271230.png

And in plain text for convenience:

 

Pages = 
VAR CurrentID = MAX ( Tbl2[Aspect ID] )
VAR Res = LOOKUPVALUE ( Tbl2[Value], Tbl2[Aspect ID], CurrentID - 1 )
RETURN Res

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

Hi Alexander

 

Thanks for having a look at this.  This is great but at the moment all the sub-totals for the 'Types' are showing as 0.  Is there anyway for the DAX to get them to display correctly?  For example:

 

Pages

Horror                                 350

     2023-1                               100

     2023-2                               150

Sci-Fi                                  600

     2023-3                               250

     2024-4                               350

 

Also one of the problems with the data we have is that it isn't organised very well and the rows in the second table sometimes have the Type come before the Pages value.  For example:

 

Aspect IDTypeValue
1Pages500
2TypeHorror
3TypeSci-Fi
4Pages250
5Pages300
6TypeDrama

 

When this happens, using your DAX code we get the Type displayed in the matrix where the page numbers should be.  Is this something that we can get around?

 

Thanks again for you help.

@jimhick47,

Though my head isn't fresh at all, I've composed such a measure, which seems to work except for the grand total. I presume this measure will be very slow with a large dataset. Can you give it a try?

barritown_0-1698875920269.png

Pages = 
VAR CurrentID = MAX ( Tbl2[Aspect ID] )
VAR CurrentVal = MAX ( Tbl2[Value] )
VAR LookupID = IF ( ISEVEN ( CurrentID ), CurrentID - 1, CurrentID + 1 )
VAR Res = LOOKUPVALUE ( Tbl2[Value], Tbl2[Aspect ID], LookupID )
VAR AffectedIDs = SELECTCOLUMNS ( FILTER ( ALL ( Tbl2 ), Tbl2[Value] = CurrentVal ), "ID", [Aspect ID] ) 
VAR CalculatedIDs = SELECTCOLUMNS ( ADDCOLUMNS ( AffectedIDs, "ID Values", IF ( ISEVEN ( [ID] ), [ID] - 1, [ID] + 1 ) ), "ID", [ID Values] )
VAR CalculatedValues = SELECTCOLUMNS ( FILTER ( ALL ( Tbl2 ), [Aspect ID] in CalculatedIDs ), "Val", [Value] )
VAR AltRes = SUMX ( CalculatedValues, INT ( [Val] ) )
RETURN IF ( ISFILTERED ( Tbl1[TaskIdentifier] ), Res, AltRes )

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

That's worked great, many thanks for all your help!

@jimhick47,

In order to solve the second problem, you can adjust the measure like that:

Pages = 
VAR CurrentID = MAX ( Tbl2[Aspect ID] )
VAR LookupID = IF ( ISEVEN ( CurrentID ), CurrentID - 1, CurrentID + 1 )
VAR Res = LOOKUPVALUE ( Tbl2[Value], Tbl2[Aspect ID], LookupID )
RETURN Res

 

I'll see the sub-total part of the problem when my head is fresh (hopefully tomorrow). 

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

 

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.