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.
Hello,
I have looked at other posts regarding index columns based on two columns, but i haven't been able to find a solution to my problem.
I have a DAX table with two date colomns (and some other columns but they are not important in this matter)
One date column is the purchase date and the other column is the sales date.
I would like an index column that looks something like this:
Purchase date | sales date | Index |
September 2020 | august 2020 | 1 |
September 2020 | september 2020 | 2 |
September 2020 | oktober 2020 | 3 |
September 2020 | november 2020 | 4 |
September 2020 | december 2020 | 5 |
September 2020 | january 2021 | 6 |
September 2020 | februrary 2021 | 7 |
September 2020 | marts 2021 | 8 |
September 2020 | april 2021 | 9 |
September 2020 | may 2021 | 10 |
September 2020 | june 2021 | 11 |
September 2020 | july 2021 | 12 |
September 2020 | august 2021 | 13 |
September 2020 | september 2021 | 14 |
October 2020 | oktober 2020 | 15 |
October 2020 | november 2020 | 16 |
October 2020 | december 2020 | 17 |
October 2020 | january 2021 | 18 |
October 2020 | februrary 2021 | 19 |
The logic is that the purchase month should be the primary index, and then the sales month. The index has to be continuos. My data is not sorted in this continuous fashion, which is the issue i am facing. And yes sometimes the sales date is earlier than the purchase date (don't ask why).
I hope someone can help me solve this issue. The solution has to be a calculated DAX column.
Thank you in advance.
Solved! Go to Solution.
This is done more easily in the query editor, but since you stated you need a DAX column, this one seems to work. You'll need to replace Index with your actual table name.
NewIndex =
VAR vThisValue =
INT ( CONVERT ( Index[Purchase date], DATETIME ) )
+ INT ( CONVERT ( Index[sales date], DATETIME ) ) / 100000
VAR vAdd =
ADDCOLUMNS (
Index,
"cValue",
INT ( CONVERT ( Index[Purchase date], DATETIME ) )
+ INT ( CONVERT ( Index[sales date], DATETIME ) ) / 100000
)
RETURN
RANKX ( vAdd, [cValue], vThisValue, ASC )
Note that I needed to use several Replace Values steps in the query editor to change month names to my locale (e.g., oktober, marts, februrary).
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
This is done more easily in the query editor, but since you stated you need a DAX column, this one seems to work. You'll need to replace Index with your actual table name.
NewIndex =
VAR vThisValue =
INT ( CONVERT ( Index[Purchase date], DATETIME ) )
+ INT ( CONVERT ( Index[sales date], DATETIME ) ) / 100000
VAR vAdd =
ADDCOLUMNS (
Index,
"cValue",
INT ( CONVERT ( Index[Purchase date], DATETIME ) )
+ INT ( CONVERT ( Index[sales date], DATETIME ) ) / 100000
)
RETURN
RANKX ( vAdd, [cValue], vThisValue, ASC )
Note that I needed to use several Replace Values steps in the query editor to change month names to my locale (e.g., oktober, marts, februrary).
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thank you so much, your solution worked!
@skanord , Assume they are date type column. A new column
countx(filter(Table, [Purchase date] <= earlier([Purchase date]) && [sales date] <= earlier([sales date]) ),[sales date])
Yes they are date type columns.
I tried your DAX formula, but i get duplicate values.
My result looks like this
Purchase date | Sales date | index |
juni 2020 | juni 2020 | 1 |
juni 2020 | juli 2020 | 2 |
juli 2020 | juni 2020 | 2 |
juni 2020 | august 2020 | 3 |
august 2020 | juni 2020 | 3 |
juni 2020 | september 2020 | 4 |
januar 2021 | juni 2020 | 4 |
juli 2020 | juli 2020 | 4 |
juni 2020 | oktober 2020 | 5 |
marts 2021 | juni 2020 | 5 |
august 2020 | juli 2020 | 6 |
juni 2020 | november 2020 | 6 |
april 2021 | juni 2020 | 6 |
juli 2020 | august 2020 | 6 |
juni 2020 | december 2020 | 7 |
juli 2021 | juni 2020 | 7 |
september 2020 | juli 2020 | 7 |
juni 2020 | januar 2021 | 8 |
juli 2020 | september 2020 | 8 |
juni 2020 | februar 2021 | 9 |
august 2020 | august 2020 | 9 |
januar 2021 | juli 2020 | 9 |
juli 2020 | oktober 2020 | 10 |
juni 2020 | marts 2021 | 10 |
september 2020 | august 2020 | 11 |
marts 2021 | juli 2020 | 11 |
juni 2020 | april 2021 | 11 |
oktober 2020 | august 2020 | 12 |
juli 2020 | november 2020 | 12 |
juni 2020 | maj 2021 | 12 |
august 2020 | september 2020 | 12 |
juni 2020 | juni 2021 | 13 |
april 2021 | juli 2020 | 13 |
november 2020 | august 2020 | 13 |
juli 2020 | december 2020 | 14 |
juni 2020 | juli 2021 | 14 |
august 2020 | oktober 2020 | 15 |
juni 2020 | august 2021 | 15 |
juli 2021 | juli 2020 | 15 |
september 2020 | september 2020 | 15 |
januar 2021 | august 2020 | 16 |
juni 2020 | september 2021 | 16 |
juli 2020 | januar 2021 | 16 |
@skanord , I that case add an index column in power query
https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi
How can i do that when it is a dax calculated table?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
82 | |
70 | |
61 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |