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
KristofferAJ
Helper III
Helper III

convert a measure into a column in powerquery

I have this measure which I consider moving into powerquery as it makes some problems for me as a measure.

Can a measure be created as a column in powerquery? or du I have want to re think the way I want to retrieve this data?

My goal is to be able tro get the duration from First fruit [FRUIT] sold in country to last fruit sold in country... (the country duration)

 

 

 



Time Duration fruit sold = VAR dispdate = MIN ( CTL[Site RTE Actual] ) VAR lastsoldthiscountry = CALCULATE ( MAX ( CTL[Site Last Actual] ), ALL ( CTL ), SUMMARIZE ( CTL, CTL[FRUIT], CTL[Country Name] ) ) RETURN IF ( NOT ( ISBLANK ( lastsoldthiscountry ) ) && NOT ( ISBLANK ( dispdate ) ), INT ( lastsoldthiscountry - dispdate ) )

Excel data:
https://www.dropbox.com/s/05a70bzjms8cqdu/Test_data.xlsx?dl=0

 

Pbix:
https://www.dropbox.com/s/ljnyics6d7n74oc/test.pbix?dl=0

 

 

Alternatively

2 ACCEPTED SOLUTIONS

v-rzhou-msft
Community Support
Community Support

Hi @KristofferAJ ,

 

You just need to create a custom column in Power Query Editor.

let _lastsoldthiscountry = 
List.Max(
    let country = [Country],
        fruit = [Fruit]
    in Table.SelectRows(#"Changed Type", 
    each [Country] = country and [Fruit] = fruit)[Last sold date]),
    _dispath = [Dispath]
in 
if _lastsoldthiscountry <> null and _dispath <> null
then Number.From( _lastsoldthiscountry - _dispath)
else null

RicoZhou_0-1653379593136.png

Then change the date type to whole number and the result is as below.

RicoZhou_1-1653379622265.png

 

Best Regards,
Rico Zhou

 

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
v-rzhou-msft
Community Support
Community Support

Hi @KristofferAJ ,

 

You just need to create a custom column in Power Query Editor.

let _lastsoldthiscountry = 
List.Max(
    let country = [Country],
        fruit = [Fruit]
    in Table.SelectRows(#"Changed Type", 
    each [Country] = country and [Fruit] = fruit)[Last sold date]),
    _dispath = [Dispath]
in 
if _lastsoldthiscountry <> null and _dispath <> null
then Number.From( _lastsoldthiscountry - _dispath)
else null

RicoZhou_0-1653379593136.png

Then change the date type to whole number and the result is as below.

RicoZhou_1-1653379622265.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

KristofferAJ
Helper III
Helper III

This is SPOT ON, thanks for that!

sturlaws
Resident Rockstar
Resident Rockstar

Hi, @KristofferAJ

 

that depends on your scenario. If you need the measure to respond to filtering in the report, the answer is No. Otherwise it is in principle doable.

 

Cheers,
Sturla

ghoshabhijeet
Solution Supplier
Solution Supplier

@KristofferAJ  Please provide the below details. Thanks !

1. Sample data or PBIX file with sample data

2. Expected Output

 

Hi @ghoshabhijeet  and @sturlaws 
Thanks for your response, I have updated with data.

This might not be as complicated as I make it.

My main goal is to be able to calculate the longest time between fruits sold per country.

But I want to have the calculation to restrict to the type of fruit and country.

For instance, the time between first dispatched ORANGE in germany to last sols ORANGE in Germany.

This measure does the job, but needing this calculation to other things I run into issues with circular dependicies and I'm considering doing it differently, either

1. As a column in powerquery with the hope it will be possible
2. Consider as a new table having powerquery to to make a column with MAX date per fruit per country which I can get by 'RELATED'

I hope these thoughts makes sense

Try this

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.