cancel
Showing results for 
Search instead for 
Did you mean: 
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
Community Champion
Community Champion

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
Community Champion
Community Champion

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
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors