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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
timstacy1
Frequent Visitor

For each distinct string value, find the last date and tell me the value in the third column

Objective

For each distrinct value, find the latest date in the second column and the corresponding text value in the third column.

 

I have three columns:  Guest, Host and Report Date.  For each guest, I need to find the corresponding host name for the latest date. Yet,  each guest has multiple hosts on different dates.  Here is an example:

GuestHostReport Date
Server AHost A12/1/2016
Server AHost A12/5/2016
Server AHost B12/19/2016

 

  

The last row is the value I want to return.  The Guest list is about 20,000 long so I want to return for each distrinct guest, a host name and the latest report date.

 

Thank you,

 

Tim

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @timstacy1,

 

You can use below measure to get the lastdate of each host.

 

maxDate=
var currGuest= lastNoBlan(Table[Guest],[Guest])
var currHost=lastNoBlan(Table[Host],[Host])
Return
MAXX(Filter(ALL(Table),[Guest]=currGuest&&[Host]=currHost),[Report Date])

 

Use [Guest], [Host] and above measure to create a table visual and you will get the result which you want.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

9 REPLIES 9
v-shex-msft
Community Support
Community Support

Hi @timstacy1,

 

You can use below measure to get the lastdate of each host.

 

maxDate=
var currGuest= lastNoBlan(Table[Guest],[Guest])
var currHost=lastNoBlan(Table[Host],[Host])
Return
MAXX(Filter(ALL(Table),[Guest]=currGuest&&[Host]=currHost),[Report Date])

 

Use [Guest], [Host] and above measure to create a table visual and you will get the result which you want.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

This is a clean solution.  Thank you.   The only change is to replace the typo to LASTNONBLANK.  

 

timstacy1
Frequent Visitor

Thank you.  Here is the result I get:

 

"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."  I copied your formula exactly.  Could I have formatted the data incorrectly?

 

 

 

MaxReportDateHost(ByGuest)=
VAR vRELEVANTDATE = [MaxReportDate(ByGuest)]
VAR vCOUNTHOSTS = CALCULATE(DISTINCTCOUNT(Table[Host]), FILTER(Table, Table[Report Date] = vRELEVANTDATE))

RETURN
IF( vCOUNTHOSTS > 1, "Multiple",
CALCULATE(
      VALUES(Table[Host]),
      FILTER(Table,
           Table[Report Date] = vRELEVANTDATE
      )
)

 

Sorry I was a little sloppy with my DAX 🙂 This should be better

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂

Thank you.  When I first create the measure MaxReportDate(byguest), I receive an error message indicating"... a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

 

If you are able, please confirm the measure is correct and I will try again.

 

Thank you

For my reply, I am referencing the response posted by austinsense.

 

 

Great cool dude . lets rockzzzzzzzzz

austinsense
Impactful Individual
Impactful Individual

Something to get you started ... You want to look at each distinct guest and figure out the latest date:

 

 

MaxReportDate(ByGuest)=MAXX( VALUES(Table[Guest]), Table[Report Date])

 

 

And then you also want to figure out who the host was on that date:

 

 

MaxReportDateHost(ByGuest)=
VAR vRELEVANTDATE = [MaxReportDate(ByGuest)]
VAR vCOUNTHOSTS = DISTINCOUNT(Table[Host]), FILTER(Table, Table[Report Date] = vRELEVANTDATE)
RETURN
IF( vMULTIPLEHOSTS > 1, "Multiple", CALCULATE( VALUES(Table[Host]), FILTER(Table, Table[Report Date] = vRELEVANTDATE )
)

 

I can't really test this and it probably needs some tweaking, but maybe this gets you started.

 

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂
Baskar
Resident Rockstar
Resident Rockstar

Create one calculated table , usin the below query,

 

1.JPG

 

 

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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