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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Multi-Conditional Lookups

Below is a simplified example of a very large data set I am working with. The goal is to consolidate data based on the tracking number.

 

I have two tables, one with a large amount of raw data, showing me every transaction related to a specific tracking number, and I created a table that summarizes the tracking numbers where I will be doing all my calculations. There are two issues I am running into with calculating the data. 

 

1. Zone

I cannot LOOKUP the zone since at times the data changes. I need to ask for the most recent, non-blank transaction for zone. 

 

2. Weight

I cannot LOOKUP or SUM weight since most often a change in weight is a correction. I need to ask for the most recent, non-blank, non-zero transaction for weight. 

 

Tracking NumberdateWeightZone
10011/1/20191250
10011/2/2019 101
10021/3/20195101
10021/4/20196250
10021/5/20190 

 

Thoughts?

10 REPLIES 10
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

Have you solved your problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, please feel free to ask.

Best  Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Since you have robust line-by-line data, you might be able to try a measures like this:

 

Zone= CALCULATE('Table'[Zone], FILTER(ALL([Transaction Date]) ,  MAX([Transaction Date])))

Weight= CALCULATE('Table'[Weight], FILTER(ALL([Transaction Date]) ,  MAX([Transaction Date])))

 

If you drag these onto your table is should do this for each tracking number.

 

Sorry I just saw that it needs to not be blank as well. Try creating this measure:

 

Zone = 
// Create Table Filtered by blanks
VAR __table1 = FILTER('Your Table',[Zone]<>Blank())
// Create a table that just holds the record we want
VAR _table2 = FILTER(_table1,max('Transaction Date/Time'))
//Get the zone
VAR _zone= calculatetable(_table2,max([Zone])
return
_zone

You should be able to do the sasme with weight, just replace the [Zone] with [Weight] and rename _zone to _weight.

 

Anonymous
Not applicable

Thanks for your reply! Two questions/comments:

 

1) I am getting a syntax error for 'return'. Thoughts?

 

2) I don't understand the max(zone) part. I am not looking for the largest zone, I am looking for the zone that corresponds to the most recent date. 

Anonymous
Not applicable


1) I am getting a syntax error for 'return'. Thoughts?


Hmm, that's interesting. Make sure I didn't something silly like leave out a paranthesis somewhere. I'm not exactly sure what would cause that. can you post a screenshot?

 


2) I don't understand the max(zone) part. I am not looking for the largest zone, I am looking for the zone that corresponds to the most recent date. 


When we write measures, the have to be aggregated. We already narrowed the table essentially down to just one row, so there will only be one value. We just put max so that the measure will accept it.

Anonymous
Not applicable

You were correct, there was a missing parenthesis - my fault entirely. 

 

Here is the current error I am receiving: 

 

Annotation 2019-07-10 125900.png

Anonymous
Not applicable

Oops, try changing

calculatetable(_table2,max([Zone]))

to 

sumx(_table2,[Zone])

 

 

Anonymous
Not applicable

I tried your solution and now I'm having a new issue. 

 

While it did produce error-free results, the problem is it is now summing all the zones in table2. 

 

I am unsure how to proceed @Anonymous 

 

Annotation 2019-07-15 115241.png

 

If I try the second option by @Iamnvt 

 

Annotation 2019-07-15 120709.png

Anonymous
Not applicable

Sorry about that, let me take another crack at it. Swapping out the sumx() line again:

 

calculate(max([Zone]),_table2)

I think my original mistake was using calculatetable() where a calculate() was supposed to be. 

 

Iamnvt
Continued Contributor
Continued Contributor

Non-blank, lastdate zone = 

VAR _table2 = CALCULATETABLE(FILTER(Table1, Table1[date] = MAX(Table1[date])), Table1[Zone] <> BLANK())

return
CALCULATE(MAX('Table1'[Zone]), _table2)

look likes you entered a different measure than my measure.

There is no _table1 there

@Anonymous 

Iamnvt
Continued Contributor
Continued Contributor

hi,

@Anonymous 

you can try this Measure:

Non-blank, lastdate zone = 

VAR _table2 = CALCULATETABLE(FILTER(Table1, Table1[date] = MAX(Table1[date])), Table1[Zone] <> BLANK())

return
CALCULATE(MAX('Table1'[Zone]), _table2)

 

here is PBI file:

https://1drv.ms/u/s!Aps8poidQa5zk6sAwEZ4y0m_xZfwWg

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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