Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have table contains partno,location, col1,col2,measur1,measure2,measure3. Based on Measure3 has to show top 100 records.

the thing is table loading two months of data. for eg. jan + feb data loading. based on partno, location, if any duplicate records has to take latest record. in sql query working. in sql query summing of two months data, ie. jan =dec+jan, feb =feb+jan, ranking on them and taking rank 1. in thisway getting latest record. How it is achieved in power bi using dax. no date table or column. having montho. for eg:nov2023=23, dec2023=24, jan2024=25, feb2024=26, mar2024=27 and so on.

having slicers partno,location. and in the table has to show serial number 1 to 100 for those records.

What I have tried:

createdmeasure to show top 50. its ok , but need is to get latest record.
Posted

1 solution

You seriously need to change your DB to achieve this in any meaningful way: storing date based data in strings is always a poor idea and string comparisons are always based on the first different pair of characters - subsequent ones aren't even looked at. So the order would be:
apr2022
apr2023
aug2022
aug2023
dec2022
dec2023
feb2022
feb2023
jan2022
jul2022
jul2023
jun2022
jun2023
mar2022
mar2023
may2022
may2023
nov2022
nov2023
oct2022
oct2023
sep2022
sep2023
Which is pretty much useless.

While it's possible to do it, it takes a lot of effort - and luck: one French or German month name will mess your code right up for example.

The CAST function will let you do it:
SQL
CAST('oct2023' AS DATE)
Will give you 2023-10-01 but it'll add a lot of processing and complexity to your queries - all of them - and still won't give you the ordering you need within each month because your data doesn't contain it: all dates will be the first of the month. And it'll hit performance as well as your number of rows grows.

At the very least, add a timestamp column (DATETIME or DATETIME2) to your DB and default it to the insert time (in UTC by preference) and use that instead of the string based junk you currently have.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900