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

Calculate table and then column based on a date selection

So this is my issue.

 

I have a table that shows Entries / In Date / Out Date , to summarize.

 

I want to show to the user the number of items according to a aging category.

 

So my first step is to calculate aging ... Aging = Datediff([In Date], [Out Date], Day), and then I created another column with the name Category which has Switch([Aging], <10, " 0 - 10 days", < 20 , "10 - 20 days" ......) and so on.

 

Then I create a visual with the category calculated in the axis and a count on the values.

 

So far so good,

 

But my issue starts when I want to give the user the freedom to choose the date (out date). So insted of calculating the diff between 2 static dates, the end date will depend on the date the user selects.

 

So my tbale is like this.

 

IdCustomerIn DateOut DateSelected DateAging
E2114649217/21/20219/22/2021  
E2114464327/20/20217/21/2021  
E2114614237/20/20218/22/2021  
E2114592247/19/20219/15/2021  
E2114575017/19/20217/30/2021  
E2114604227/19/20218/14/2021  
E2114583537/18/20219/2/2021  
E2114583447/18/20217/25/2021  
E2114583017/17/20218/9/2021  
E2114582827/17/20217/23/2021  
E2114575437/16/20217/20/2021  
E2114515347/16/20217/19/2021  
E2114513117/16/20217/19/2021  
E2114561927/16/20217/19/2021  
E2114461037/15/20217/16/2021  
E2114432047/15/20217/16/2021  

 

I believe the category must be calculated with a column so I can then use it in the axis, is there a way to achieve this?

 

I do have a date table NOT related to this one, so I guess I can use that one somehow.

 

the whole reasoning is that I want to know the inventory aging, so If the user selects 7/31/2021, then the final visual should not show anything that got in after that date.

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

Hi @garzamalan 

Please correct me if I wrongly understood your issue .

You want users can select [out date] freedomly and use the date they choose as a deadline .If they choose the date “ 7/31/2021” , the value of the date after “ 7/31/2021” will not display in the visual , right ?If in this case , I create a sample , you can refer to it .

(1)Create a new table with the field from Main data table .We will get a new date table with the column [Out Date]

Date = SELECTCOLUMNS('Main data',"Date",'Main data'[Out Date])

(2)Create a slicer with field [Date] from Date table .

Ailsamsft_0-1632894780994.png

(3)Through creating a measure to return the date before the date selected in Date table .

Measure = CALCULATE(SELECTEDVALUE('Main data'[Out Date]),FILTER('Main data','Main data'[Out Date]<=MAX('Date'[Date])))

(4)Put the measure in visual filter and set the measure is not blank .

Ailsamsft_3-1632894902818.png

And the final result is as shown :

Ailsamsft_1-1632894780997.pngAilsamsft_2-1632894781000.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yetao1-msft
Community Support
Community Support

Hi @garzamalan 

Please correct me if I wrongly understood your issue .

You want users can select [out date] freedomly and use the date they choose as a deadline .If they choose the date “ 7/31/2021” , the value of the date after “ 7/31/2021” will not display in the visual , right ?If in this case , I create a sample , you can refer to it .

(1)Create a new table with the field from Main data table .We will get a new date table with the column [Out Date]

Date = SELECTCOLUMNS('Main data',"Date",'Main data'[Out Date])

(2)Create a slicer with field [Date] from Date table .

Ailsamsft_0-1632894780994.png

(3)Through creating a measure to return the date before the date selected in Date table .

Measure = CALCULATE(SELECTEDVALUE('Main data'[Out Date]),FILTER('Main data','Main data'[Out Date]<=MAX('Date'[Date])))

(4)Put the measure in visual filter and set the measure is not blank .

Ailsamsft_3-1632894902818.png

And the final result is as shown :

Ailsamsft_1-1632894780997.pngAilsamsft_2-1632894781000.png

I have attached my pbix file ,you can refer to it .

 

Best Regards

Community Support Team _ Ailsa Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

"But my issue starts when I want to give the user the freedom to choose the date (out date). So insted of calculating the diff between 2 static dates, the end date will depend on the date the user selects."

 

At that point you ca no longer use calculated columns. You need to switch to measures.

 

It is not clear what the user experience would look like though - would you expect the user selected out date to overrule the recorded out date?

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.