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
Ahmedelshark
Helper I
Helper I

Displaying a Value in Card Visual Based on Date Chosen

Hello all,

 

I am currently working on a report with two visuals - a Card Visual displaying the 'L Value' and a Date Range Slicer Visual for selecting date range. 

 

I am trying to get the Card Visual to display the latest 'L Value' based on the date range chosen - see data extract below. For example, if date range chosen is 10 Nov (start) - 12 Nov (end), 'L Value in the card visual should be 0.36. If the date range chosen is 12 Nov (start) - 15 Nov (end), 'L Value' should be 0.45.

 

Every time I've tried doing it, I get a choice of displaying the sum / average / min / max / count / etc. of the 'L Value' column. All I want is the last corresponding 'L Value' for the end date chosen.

 

Any help would be appreciated. Thanks guys!

 

TitleDateHoursL Value
Partner10-Nov-190.50.00
Associate12-Nov-191.22.40
Partner12-Nov-1920.48
Partner12-Nov-190.80.36
Partner13-Nov-1910.28
Associate14-Nov-1931.80
Associate15-Nov-193.51.09
Partner15-Nov-1910.45
2 ACCEPTED SOLUTIONS

Hi @Ahmedelshark ,

 

Yes, it's doable, but you need to do a quick addition in Power Query first: you need to add an index column to your table.

In Power Query, go to New Source>Blank Query then in Advanced Editor paste my code over the default code. You can then follow the steps I took to complete this.

// Paste this in into Advanced Editor
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc8xCoAwDAXQu2TWkKat1NELiHvpIOLgoqDi+dU4tFRx+XR45P96D12/7vO4QgGKynY5SlVfb0IrSQSh8NBs2zJM/T7ejCNTyFcymocltxLEcsm4H0LoJHWVI52UCWH3XmQi0rLKfcy2CZLfKaQ6r7N5nbEQwgk=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Title = _t, Date = _t, Hours = _t, #"L Value" = _t]),
    addIndexFromOne = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    chgAllTypes = Table.TransformColumnTypes(addIndexFromOne,{{"Title", type text}, {"Date", type date}, {"Hours", type number}, {"L Value", type number}})
in
    chgAllTypes

 

You need to make sure you add the index column AFTER you've done your filtering and sorting on the table.

 

You would then create a measure like this:

_latestL = 
CALCULATE(
    MAX(AhmedesTable[L Value]),
    FILTER(
        AhmedesTable,
        AhmedesTable[Index] = MAX(AhmedesTable[Index])
    )
)

 

Which should give you the following ouput:

BA_Pete_0-1603898694790.png

 

It's worth noting from this output that the table visual does not keep the original sort order unless you use the [Index] field in it and sort on it. If you look at the output example, you can see that the visual shows 0.48 as the last row value, but the measure correctly calculates it as 0.36. Be careful not to confuse your end users with this.

 

Pete

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

Hi @Ahmedelshark ,

 

Try removing the ', Int64.Type' argument from this line.

 

*EDIT* Ignore the above, easier if you just do it directly on your data:

1) Complete any transformations on your data in Power Query

2) Sort the data how you would like it to be ordered for calculation

3) As the last step in your query, select the 'Add Column' tab above the ribbon, find th 'Index Column' button and hit it. It doesn't really matter whether your index column starts from 0 or 1, the effect is the same.

 

Pete

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

6 REPLIES 6
BA_Pete
Super User
Super User

Hi @Ahmedelshark ,

 

Do you have a time field in your table?

It makes it a bit more complicated to resolve the latest entry when working with multiple entries on the same date.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hello @BA_Pete ,

 

Thanks for replying. 

 

I do not have a time field. I was wondering whether it could be based on order in which the data has been inputted? So in the data extract provided, the last 'L value' for 12-Nov should be 0.36 (as it is the last row of data for 12 Nov).

Hi @Ahmedelshark ,

 

Yes, it's doable, but you need to do a quick addition in Power Query first: you need to add an index column to your table.

In Power Query, go to New Source>Blank Query then in Advanced Editor paste my code over the default code. You can then follow the steps I took to complete this.

// Paste this in into Advanced Editor
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fc8xCoAwDAXQu2TWkKat1NELiHvpIOLgoqDi+dU4tFRx+XR45P96D12/7vO4QgGKynY5SlVfb0IrSQSh8NBs2zJM/T7ejCNTyFcymocltxLEcsm4H0LoJHWVI52UCWH3XmQi0rLKfcy2CZLfKaQ6r7N5nbEQwgk=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Title = _t, Date = _t, Hours = _t, #"L Value" = _t]),
    addIndexFromOne = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
    chgAllTypes = Table.TransformColumnTypes(addIndexFromOne,{{"Title", type text}, {"Date", type date}, {"Hours", type number}, {"L Value", type number}})
in
    chgAllTypes

 

You need to make sure you add the index column AFTER you've done your filtering and sorting on the table.

 

You would then create a measure like this:

_latestL = 
CALCULATE(
    MAX(AhmedesTable[L Value]),
    FILTER(
        AhmedesTable,
        AhmedesTable[Index] = MAX(AhmedesTable[Index])
    )
)

 

Which should give you the following ouput:

BA_Pete_0-1603898694790.png

 

It's worth noting from this output that the table visual does not keep the original sort order unless you use the [Index] field in it and sort on it. If you look at the output example, you can see that the visual shows 0.48 as the last row value, but the measure correctly calculates it as 0.36. Be careful not to confuse your end users with this.

 

Pete

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thank you very much @BA_Pete . In pasting the code, I get the following error below:

 

Ahmedelshark_0-1603900968395.png

 

Hi @Ahmedelshark ,

 

Try removing the ', Int64.Type' argument from this line.

 

*EDIT* Ignore the above, easier if you just do it directly on your data:

1) Complete any transformations on your data in Power Query

2) Sort the data how you would like it to be ordered for calculation

3) As the last step in your query, select the 'Add Column' tab above the ribbon, find th 'Index Column' button and hit it. It doesn't really matter whether your index column starts from 0 or 1, the effect is the same.

 

Pete

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




This is great Pete. Thank you so much!

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.