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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
chetan8080
Helper I
Helper I

calculated columns to filter by max & min date

Hello Community!
I Have date field in a slicer in which 2 dates are selected ( Max& Min)
I have a problem where I need to have 2 columns of products in a table, one should give me details of products of Max date & other column should give details of products of Min date in the same table.

Thank you in Advance.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @chetan8080 
Here is a samp[le file with the solution https://we.tl/t-SeyYXbCoV0

1.png2.png3.png5.png6.png7.png

 

1.png2.png

Filter Table = 
VAR NumOfProducts = COUNTROWS ( DISTINCT ( Data[Product] ) )
VAR ProductIndexTable = GENERATESERIES ( 1, NumOfProducts, 1 )
VAR AllDatesTable = CALENDAR ( MIN ( Data[Date] ), MAX ( Data[Date] ) )
VAR DatesWithIndex = CROSSJOIN ( ProductIndexTable, AllDatesTable )
RETURN
    DatesWithIndex
Index = RANKX ( Data, Data[Product],, ASC, Dense )
Date Measure = 
MAX ( 'Filter Table'[Date] )
Product Measure = 
CALCULATE ( 
    MAX ( Data[Product] ),
    Data[Date] = MAX ('Filter Table'[Date] )
)

 

View solution in original post

7 REPLIES 7
tamerj1
Super User
Super User

Hi @chetan8080 
Here is a samp[le file with the solution https://we.tl/t-SeyYXbCoV0

1.png2.png3.png5.png6.png7.png

 

1.png2.png

Filter Table = 
VAR NumOfProducts = COUNTROWS ( DISTINCT ( Data[Product] ) )
VAR ProductIndexTable = GENERATESERIES ( 1, NumOfProducts, 1 )
VAR AllDatesTable = CALENDAR ( MIN ( Data[Date] ), MAX ( Data[Date] ) )
VAR DatesWithIndex = CROSSJOIN ( ProductIndexTable, AllDatesTable )
RETURN
    DatesWithIndex
Index = RANKX ( Data, Data[Product],, ASC, Dense )
Date Measure = 
MAX ( 'Filter Table'[Date] )
Product Measure = 
CALCULATE ( 
    MAX ( Data[Product] ),
    Data[Date] = MAX ('Filter Table'[Date] )
)

 

chetan8080
Helper I
Helper I

Hi @tamerj1 , thank you for coming up.
All the fields like date, products are from same table.

@chetan8080 

Wold you please provide sample expected results?

chetan8080_0-1656253184076.png

I have provided how the power bi table should look like, The slicer is multi-selected with 2 dates: 1/1/2022 & 2/1/2022.
The products details for 1/1/2022 should be in first column & product details of 2/1/2022 in a second column of the same table.

@chetan8080 

I was sbout to say that this cannot be achieved but I gave it another thought and I believe it can be achieved if we have an index column. I will try to produce something by tomorrow morning and get back to you. 

sure @tamerj1 , that will help a lot!!. I will be waiting for your reply.

Thank you : )

tamerj1
Super User
Super User

Hi @chetan8080 

this date field in the slicer from which table? If the same table then which column? Of another table do you have a relationship between this table and the fact table? Based on which column?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.