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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Get last value for each category but date slicer friendly

Hi everyone,

 

Here is my situation : I would like to create a sectoral visual but only showing the last item purchased by each of my customers, depending on a date slicer. So let's say I have this table :

ROW IDCLIENT NUMBERPURCHASE DATEITEM
1A01/01/2022Flowers
2B02/01/2022Clothes
3A15/01/2022Chocolate
4A01/02/2022Candy
5B13/02/2022Kitchenware
6C15/02/2022Soap
7C27/02/2022Gameboy

 

If i'm selecting a range period of time between 01/01/2022 and 31/01/2022, I need the table to show :

ROW IDCLIENT NUMBERPURCHASE DATEITEM
2B02/01/2022Clothes
3A15/01/2022Chocolate

 

If I'm selecting a range period of time between 15/01/2022 and 27/02/2022, I need the table to show :

ROW IDCLIENT NUMBERPURCHASE DATEITEM
4A01/02/2022Candy
5B13/02/2022Kitchenware
7C27/02/2022Gameboy

 

And if I'm selecting the whole period, it should show :

ROW IDCLIENT NUMBERPURCHASE DATEITEM
4A01/02/2022Candy
5B13/02/2022Kitchenware
7C27/02/2022Gameboy

 

The idea would be to then have the sectoral visual, using the "client number" as values and "item" as detail :

Elodie_1-1644571786853.png

 

I've tried many measures to apply them as filters on my visual but nothing seems to work. I would be very grateful if you can help me on this one!

1 ACCEPTED SOLUTION
ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

For the tables use this kind of logic:

Measure 18 =

var Ldate = LASTDATE('Table (7)'[PURCHASE DATE]) return
calculate(MAX('Table (7)'[ITEM]),'Table (7)'[PURCHASE DATE]=Ldate)
 
Measure 19 = LASTDATE('Table (7)'[PURCHASE DATE])
 
 
ValtteriN_0-1644577084072.png



For the graph:

 

Measure 20 =
var client = MAX('Table (7)'[CLIENT NUMBER])
var Ldate = CALCULATE(MAX('Table (7)'[PURCHASE DATE]),ALL('Table (7)'),'Table (7)'[PURCHASE DATE]<=MAX('Calendar'[Date]),'Table (7)'[CLIENT NUMBER]=client) return

if(MAX('Table (7)'[PURCHASE DATE])=Ldate,1,0)

 
ValtteriN_1-1644577165947.png

Note that I don't have a relationship between calendar and the test table. Here I use calendar for slicer.


ping me with @ if you have questions.


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Anonymous 

Here is the sample file with solution https://www.dropbox.com/t/Yj42dvuDm4iOC6R7
You can use the following code for all measures just change the name of the column 

Last Item = 
VAR LastVisibleDate = MAX ('Date'[Date] )
VAR Result =
    CALCULATE ( 
        SELECTEDVALUE ( Data[Item] ),
        FILTER (
            Data,
            Data[PURCHASE DATE] = LastVisibleDate
        )
    )
RETURN
    Result 

Untitled.png
Please let me know if you have any further question.
If my reply answers your query please mark it as accepted solution. Thank you 

ValtteriN
Super User
Super User

Hi,

Here is one way to do this:

For the tables use this kind of logic:

Measure 18 =

var Ldate = LASTDATE('Table (7)'[PURCHASE DATE]) return
calculate(MAX('Table (7)'[ITEM]),'Table (7)'[PURCHASE DATE]=Ldate)
 
Measure 19 = LASTDATE('Table (7)'[PURCHASE DATE])
 
 
ValtteriN_0-1644577084072.png



For the graph:

 

Measure 20 =
var client = MAX('Table (7)'[CLIENT NUMBER])
var Ldate = CALCULATE(MAX('Table (7)'[PURCHASE DATE]),ALL('Table (7)'),'Table (7)'[PURCHASE DATE]<=MAX('Calendar'[Date]),'Table (7)'[CLIENT NUMBER]=client) return

if(MAX('Table (7)'[PURCHASE DATE])=Ldate,1,0)

 
ValtteriN_1-1644577165947.png

Note that I don't have a relationship between calendar and the test table. Here I use calendar for slicer.


ping me with @ if you have questions.


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hello @ValtteriN and thank you for your answer.

I've tried reproducing your visual but I can't make it work. Can I see in which fields did you put the measures?

Hi,

Here is a snippet of the visual:

ValtteriN_0-1644835821322.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors