cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Anonymous
Not applicable

## How to sort data based on date

I am trying to sort  data  on my power BI report  based on one column in one table based and  date column from another table in  , i wanted to know if there is a DAX function   for sorting data in this way

1 ACCEPTED SOLUTION
Resolver III

But in that case wouldn't it just sort by Descending date?
I apologize for the questions, but I want to better understand to help you properly.

Please mark as solution so others can find this solution.

13 REPLIES 13
Anonymous
Not applicable

my syntax correct though?

Resolver III

What you will have to do is create a column that transforms the date into numeric code and sort by it.

12/01/2020 = 20201201

Please mark as solution so others can find this solution.

Resolver III

Hello, how are you?
I don't know if it's your case.
But if you have a date table and it is correctly related to your fact table.
Just go to Power Pivot, select your date table and sort the name of the month based on the numeric month column.

Please mark as solution so others can find this solution.

Anonymous
Not applicable

This is different from what i want to do, i dont have  date table , but i do have table (fact) that has date column and another table (dim) that has the  product ID. so i wanted to sort prodct ID based on the date

Resolver III

Could you share a sample of your data.
Or a fictional base.

Please mark as solution so others can find this solution.

Anonymous
Not applicable

Here, D is the date column, and P, is the product ID,  in this screenshot, i would like say the 1/12/20 date and the product ID,s ending with 791 to be at the top

Resolver III

I understood.
My question is what would be the criterion that you will adopt based on the data to consider 139791 and 12/01/20 as the first item on the list.
After knowing this sorting logic, we have a route to follow.

Please mark as solution so others can find this solution.

Anonymous
Not applicable

Beacuase thats the newest date , it should be at the top

Resolver III

But in that case wouldn't it just sort by Descending date?
I apologize for the questions, but I want to better understand to help you properly.

Please mark as solution so others can find this solution.

Anonymous
Not applicable

I am trying to sort by that and i dont think i finding the place to do that, when i go to the model tab and select that column then try to sort, its not showing the output i need, its just showing all the date without any sort order

Resolver III

Create a custom column in Power Query:

= Table.AddColumn(#"Changed Type", "KeyId", each Text.Combine({Date.ToText([Date], "yyyy"), Date.ToText([Date], "%M"), Date.ToText([Date], "dd")}), type text)

then set this column as number:

Please mark as solution so others can find this solution.

Anonymous
Not applicable

I tried this code and my column shows "table"

--here is my code

Table.AddColumn(#"Changed Type", "KeyId", each Text.Combine({Date.ToText([orderdate], "yyyy"), Date.ToText([orderdate], "%M"), Date.ToText([orderdate], "dd")}), type text)

Resolver III

You can share a file with a faithful sample of your data so I can test it.

Please mark as solution so others can find this solution.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors