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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
mgrayTCB
Helper III
Helper III

relating or looking up values in virtual tables

I have vitual tables each one shows the expected sales dates for a particular project. One is based on the budgeted date and the other is based on the current dates. I want to compare the 1st current date to the 1st budget date and then the 2nd current date to the 2nd budget date, and so on. I created a meausre that indexes them 1,2,3,n [CENumber] with the thoguht that I could match them up and calcualte the difference in dates.

 

I cant seem to figure out how to relate or lookup the date values between these tables in order to calcualte the difference and then sum the total delay. Any help would be appreciated

 

Below is the code that gets me each of the tables for a particular project and year but I am stuck on how to relate or look up dates between them to calculate the difference.

 

var _projname ="Marshall Gardens"

var _TableCurrent =
ADDCOLUMNS(
SELECTCOLUMNS(
CALCULATETABLE(
FILTER(
dimDate,
[NetFeeCurrent]>0),
// filter down to year and prject
FILTER(dimDate,dimDate[Date].[Year] = 2022),
FILTER(Project,Project[ProjectName] = _projname)
),
"dateCurrent",[Date]),
"CENumber",[NumberSelectedDates]
)

var _TableBudget =
ADDCOLUMNS(
SELECTCOLUMNS(
CALCULATETABLE(
FILTER(
dimDate,
[NetFeeBudget]>0),
// filter down to year and prject
FILTER(dimDate,dimDate[Date].[Year] = 2022),
FILTER(Project,Project[ProjectName] = _projname)
),
"dateBudget",[Date]),
"CENumber",[NumberSelectedDates]
)

 

1 ACCEPTED SOLUTION

Hi @mgrayTCB ,

 

I think you're ignoring the parentheses of Table.Sort function. Please try this:

= Table.AddIndexColumn( Table.Sort( [Group], { {"Date",  Order.Ascending} } ), "Index", 1, 1, Int64.Type )

 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@mgrayTCB , when you have the common date and project taking a diff measure at a visual level between measures from two tables for the displayed column

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you for thinking about this. Here is a bit more detail. I have a budget table(DevRevenueBudget) and a Current table (DevRevenue). Budget was frozen at the begining of the year. Each project has a series of sales events they were sechedule on cetrain dates at budget time but now have updated (current dates). I want to calculate the delay. See model and expected result.

 

mgrayTCB_1-1644249254506.png

 

 

mgrayTCB_0-1644249230816.png

 

Hi @mgrayTCB ,

 

Not sure if I understand correctly. I create the following example data. =

 

vkkfmsft_0-1644473437913.png

vkkfmsft_1-1644473462663.png   vkkfmsft_2-1644473472541.png

 

Then add index to pre group. 

 

 #"Grouped Rows" = Table.Group(#"Changed Type", {"ProjectID"}, {{"Group", each _, type table [Date=nullable date, ProjectID=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn(Table.Sort([Group],{{"Date", Order.Ascending}}), "Index", 1, 1, Int64.Type)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Date", "ProjectID", "Index"}, {"Date", "ProjectID", "Index"})

vkkfmsft_3-1644473550498.png

 

Create calaulated table [Index] and create relationship with table [DevRevenueBudget] and [DevRevenue]. 

 

Index = 
DISTINCT (
    UNION ( VALUES ( DevRevenue[Index] ), VALUES ( DevRevenueBudget[Index] ) )
)

vkkfmsft_4-1644473614094.png

 

Then create the measure.

 

Measure = 
DATEDIFF (
    SELECTEDVALUE ( DevRevenue[Date] ),
    SELECTEDVALUE ( DevRevenueBudget[Date] ),
    DAY
)

vkkfmsft_5-1644473642463.png   vkkfmsft_6-1644473651309.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

I am working though this and trying to add the index to the revenue table. I got the grouping step to work but cant get the index step to work. I keep getting this error:

mgrayTCB_0-1644514505884.png

This is the M code I am trying to add in the Add Custom column step. 

 

Table.AddIndexColumn(Table.Sort[Group],{{"DateActOrEst",Order.Ascending}},"Index",1,1,Int64.Type)

This was taken right from your example other than the name of the date field.

Hi @mgrayTCB ,

 

I think you're ignoring the parentheses of Table.Sort function. Please try this:

= Table.AddIndexColumn( Table.Sort( [Group], { {"Date",  Order.Ascending} } ), "Index", 1, 1, Int64.Type )

 

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is very helpful. I will work through this solution with my data and let you know if I have any questions

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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