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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Rup10
Resolver I
Resolver I

Help needed for Cast and lag function

Hi,

I need to add one custom column called "rank" by using below expression : 

sum(cast(booked != lag(booked,1)

 

Can Someone please help with the DAX/Measure expression.

Thanks in advance

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @Rup10 ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it.

 

Best Regards,
Eyelyn Qin

v-eqin-msft
Community Support
Community Support

Hi @Rup10 ,

 

Based on my researching, the LAG function returns values from a previous row in the table and the CAST function converts an expression from one datatype to another datatype.

 

But actually I'm not sure about your expected output, could please share more detail information to help us clarify your scenario?

 

In case you want the final result as shown below:

3.18.1.RANK.PNG

Please try LOOKUPVALUE() , RANKX() to add columns after adding a Index column in Power Query

3.18.1.INDEX.PNG

CAST =
IF (
    [BOOKED]
        <> LOOKUPVALUE ( 'Table'[BOOKED], 'Table'[Index], [Index] - 1 ),
    1,
    0
)
rankColumn =
RANKX ( 'Table', [BOOKED],, ASC, DENSE )

 

Here is the pbix file.

 

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

amitchandak
Super User
Super User

@Rup10 ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

Please find the attached(booked column sample data) image.

booked.png

Thank you

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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