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
kressb
Helper V
Helper V

Lookupvalue using dates?

Hello, 

I am trying to divide a number in Table 1 by a number with the corresponding date in Table 2 to get a percentage.

 

Table 1
DateDecimal
3/2/20190.9
3/2/20190.05
3/16/20190.37
3/16/20190.4
3/16/20190.36
4/27/20190.02
5/11/20191.36
5/11/20190.94

 

Table 2
DateNumber
3/2/2019404.7
3/16/2019405
4/27/2019405.75
5/11/2019406.1

 

Output I want:

Output
DatePercent
3/2/20190.22%
3/2/20190.01%
3/16/20190.09%
3/16/20190.10%
3/16/20190.09%
4/27/20190.00%
5/11/20190.33%
5/11/20190.23%

 

I was trying this but it's not working:

Percentage = Divide(sum(Table1[Decimal],Lookupvalue(Table2[Number],Table2[Date],Table1[Date]),0)

 

Can Lookupvalue be used for dates?

Any help would be appreciated. TYIA. 

1 ACCEPTED SOLUTION


@Iamnvt wrote:
It looks like you are writing a Measure, not calculated column. I think you should turn off the date hierarchy to have [.Month] off.

You can go to Model tab, and insert calculated column with the said formula. Check my PBI file for more details.

Just want to close the loop on the question and address the date hierarchy. 

The date hierarchy has been off and still the .[Month] etc. comes up. 

I ended up using:

Measure = Divide(sum('Table1'[Decimal]),calculate(sum('Table2'[Number])),0)
which seems to work. TY

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

This calculated column works just fine.

Column = [Decimal]/LOOKUPVALUE(Table2[Number],Table2[Date],Table1[Date])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/


@Ashish_Mathur wrote:

Hi,

This calculated column works just fine.

Column = [Decimal]/LOOKUPVALUE(Table2[Number],Table2[Date],Table1[Date])

Hope this helps.

 


This doesn't work at all for me. 

It says: "The value for 'Decimal' cannot be determined. Either 'Decimal' doesn't exist, or there is no current row for a column named 'Decimal'.

 

?? please let me know if you have any ideas.

Hi,

I cannot understand why it is not working.  As can be seen in my screenshot, my formula works fine.  I hope you are writing it as a calculated column formula (not as a measure).


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Iamnvt
Continued Contributor
Continued Contributor

hi,

 

you can use calculated column:

Calculated Column % = DIVIDE(Table1[Decimal], LOOKUPVALUE(Table2[Number],Table2[Date],Table1[Date]))

here is the PBI file:

https://1drv.ms/u/s!Aps8poidQa5zk6pa5KcbigH1gCmIYg

 


@Iamnvt wrote:

hi,

 

you can use calculated column:

Calculated Column % = DIVIDE(Table1[Decimal], LOOKUPVALUE(Table2[Number],Table2[Date],Table1[Date]))

here is the PBI file:

https://1drv.ms/u/s!Aps8poidQa5zk6pa5KcbigH1gCmIYg

 


I took it back a step and tried just getting the "Lookupvalue" function to work. 

Each time when I get to "Table2[Date] I get options for ".Date" ".Month" etc and after I chose one there is no option to pick "Table1[Date]" as my third attribute.

 

If I manually type over or copy and paste what you have above, I get this error:

"A single value for column 'Date' in table 'Table1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

 

Please let me know if you have any ideas on the error? TY.

 

Iamnvt
Continued Contributor
Continued Contributor

It looks like you are writing a Measure, not calculated column. I think you should turn off the date hierarchy to have [.Month] off.

You can go to Model tab, and insert calculated column with the said formula. Check my PBI file for more details.


@Iamnvt wrote:
It looks like you are writing a Measure, not calculated column. I think you should turn off the date hierarchy to have [.Month] off.

You can go to Model tab, and insert calculated column with the said formula. Check my PBI file for more details.

Just want to close the loop on the question and address the date hierarchy. 

The date hierarchy has been off and still the .[Month] etc. comes up. 

I ended up using:

Measure = Divide(sum('Table1'[Decimal]),calculate(sum('Table2'[Number])),0)
which seems to work. TY

Hello, thank you for responding. What is the difference between what you posted and what I have in my question? The only difference I see is the "sum" portion. My issue is the lookupvalue does not work when I write it that way. After I put in the date column, I get a drop down that gives the following choices: .[Date], .[Day], .[Month], .[MonthNo], .[Quarter], .[QuarterNo], .[Year]

 

no matter which one I pick, it doesn't work. 

Could it be an issue with the relationship between the tables?

 

Iamnvt
Continued Contributor
Continued Contributor

Hi,

In calculated column, it is refer to row context. When you use SUM in row context, it will sum up all the row values. You need to enable context transition to make SUM refer to one row.

You can do that by wrap up SUM with CALCULATE —> Calculate(Sum([Values]))

You need to have a separate Calendar table to link between the 2 tables. If that the case, then you dont need to use lookupvalue, but just DIVDE(SUM([Decimal],sum([Number]))

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.