I have a data set containing: Accounts selling various fruits in various countries, im working on some metrics and I really want to calculate the time between the first sold fruit in a country to the last sold fruit in the same country.
For instance: "days between" First sold ORANGE in Austria to Last sold ORANGE in AUSTRIA
I have solved this using a measure, which works but this doesn't allow me to work further with it as it throws me error with circular dependicies (ALL reference!)
I wonder if I can do this less complicated? an idea would be to set up an additional table in powerquery having latest date sold by fruit and country similar to what a pivot can do in excel, after that I could link to my main table and retrieve the date by using the RELATED option.
Any ideas?
Current muesure in powerBI:
DURATION =
VAR dispdate =
MIN( 'Test dat'[Dispath] )
VAR lastsoldthiscountry =
CALCULATE(
MAX( 'Test dat'[Last sold date] ),
ALL( 'Test dat' ),
SUMMARIZE( 'Test dat', 'Test dat'[Fruit], 'Test dat'[Country] )
)
RETURN
IF(
NOT ( ISBLANK( lastsoldthiscountry ) ) && NOT ( ISBLANK(dispdate) ),
INT( lastsoldthiscountry - dispdate )
)
Excel raw test: https://www.dropbox.com/scl/fi/cppyzagm4ahusrxmadlg6/Test_data_withPivot.xlsx?dl=0&rlkey=2nf5wzl7etwr2hqg2lh4oyifx
PBI file: https://www.dropbox.com/s/ljnyics6d7n74oc/test.pbix?dl=0
