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

Distinct search/lookup

Hi all,

 

I have a little challenge where I struggle with and hope to find help here in this great community. What is the challenge?  For a certain material I need to search for the standard price valid in Sep 2021. In my table there might be a valid entry for this month and year, but not necessarily. If not available I would like to have the standard price with the closest earlier record to 09/2021. E.g. if there are records for 08/2021 and 07/2021 available then I would like to have only 08/2021 .  If there are only records available after 09/2021, then the expression should result in 0. 

 

As you can see in the table below for Material A it should select the record where year+period is 2030, for material B the record where year+period is 2029 ( there is no 2030 record and hence it should select the closest earlier record, namely August record). For material C July 2021 is the closest earlier record. And for material D no record should be selected as the records were created later than 09/2021

 

Is there any smart way in doing this?

 

Thank you in advance

 

Br

Harry

MaterialYearPeYear+Period Standard price 
202182029                                        8
202192030                                        9
2021102031                                      10
B202152026                                        2
B202162027                                        3
B202182029                                        4
B2021102031                                        5
C202112022                                        1
C202152026                                        2
C202162027                                        3
C202172028                                        4
D2021102031                                        1
D2021112032                                        2
D2021122033                                        3
     
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Harry1980 

try to plot a table with the material column and a measure like this:

Standard Price = 
VAR _targetmonth = 9
VAR _targetyear =2021   // the first two lines could be replaced other ways
VAR _material = MAX(TableName[Material])
VAR _table =     
FILTER(
        TableName, 
        TableName[Material]=_material
            &&TableName[Year] = _targetyear
            &&TableName[Pe] <= _targetmonth
    )

VAR _month = 
MAXX(
    _table,
    TableName[Pe]
)
RETURN 
MAXX(
    FILTER(_table, TableName[Pe]=_month),
    TableName[ Standard price ]
)

 

i tried and it worked like this:

FreemanZ_0-1672931771044.png

View solution in original post

3 REPLIES 3
Harry1980
Helper I
Helper I

thank you very much for your support. It is highly appreciated

johnt75
Super User
Super User

Try

Standard price = SELECTCOLUMNS(
	CALCULATETABLE(
		TOPN( 1,
			'Table',
			'Table'[Year], DESC, 'Table'[Pe], DESC 
		),
		ALLEXCEPT( 'Table', 'Table'[Material]),
		'Table'[Year] < 2021 || ( 'Table'[Year] = 2021 && 'Table'[Pe] <= 9 )
	),
	"@val", 'Table'[Year+Period]
)
FreemanZ
Super User
Super User

hi @Harry1980 

try to plot a table with the material column and a measure like this:

Standard Price = 
VAR _targetmonth = 9
VAR _targetyear =2021   // the first two lines could be replaced other ways
VAR _material = MAX(TableName[Material])
VAR _table =     
FILTER(
        TableName, 
        TableName[Material]=_material
            &&TableName[Year] = _targetyear
            &&TableName[Pe] <= _targetmonth
    )

VAR _month = 
MAXX(
    _table,
    TableName[Pe]
)
RETURN 
MAXX(
    FILTER(_table, TableName[Pe]=_month),
    TableName[ Standard price ]
)

 

i tried and it worked like this:

FreemanZ_0-1672931771044.png

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.