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
casamontagna
Frequent Visitor

find minimum value of a group and display 2 relevant columns

Dears,

 

i am sure there is a simple solution, but i am struggling on the following problem:

I need to find the the first order date of a budget (budget = customer order in  a project) in a project. So far not a problem, i would be only searching the MIN date of a project  by grouping

. My problem is, that i need to have the information of the budget number and the project. In other words, i need only one row for each project, showing ProjectNr, budget and orderdate. if two or more budgets in a project do have the same order date, it is enough to consider just one of those.

thank you.

2020-01-24 09_06_17-BASIS_Projektphasen - Power Query-Editor.jpg

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @casamontagna 

 

just add a new grouping criteria that picks up the first budget. To get the right sort order of the budget numer, sort the date in ascending and surround it with table.buffer. Here a code example

let
	Source = #table
	(
		{"ProjectNr","budget","orderdate"},
		{
			{"A","1","43854"},	{"A","2","43853"},	{"B","1","43842"},	{"B","2","43843"}
		}
	),
    ToDate = Table.TransformColumns
    (
        Source,
        {
            {
                "orderdate",
                each Date.From(Number.From(_)),
                type date
            }
        }
    ),
    SortOrderDateAscending = Table.Buffer
    (
        Table.Sort
        (
            ToDate,
            {{"orderdate", Order.Ascending}}
        )
    ),
    GroupSpecial = Table.Group
    (
        SortOrderDateAscending, 
        {"ProjectNr"}, 
        {{"MinOrderDate", each List.Min([orderdate]), type date}, {"firstBudget", each List.First(_[budget])}}
    )
in
	GroupSpecial

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @casamontagna 

 

just add a new grouping criteria that picks up the first budget. To get the right sort order of the budget numer, sort the date in ascending and surround it with table.buffer. Here a code example

let
	Source = #table
	(
		{"ProjectNr","budget","orderdate"},
		{
			{"A","1","43854"},	{"A","2","43853"},	{"B","1","43842"},	{"B","2","43843"}
		}
	),
    ToDate = Table.TransformColumns
    (
        Source,
        {
            {
                "orderdate",
                each Date.From(Number.From(_)),
                type date
            }
        }
    ),
    SortOrderDateAscending = Table.Buffer
    (
        Table.Sort
        (
            ToDate,
            {{"orderdate", Order.Ascending}}
        )
    ),
    GroupSpecial = Table.Group
    (
        SortOrderDateAscending, 
        {"ProjectNr"}, 
        {{"MinOrderDate", each List.Min([orderdate]), type date}, {"firstBudget", each List.First(_[budget])}}
    )
in
	GroupSpecial

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

@Jimmy801  thank yo so much! made my day and saved me from futher headache 🙂

Hello @casamontagna 

thanks for the feedback. It's very appreciated

 

Jimmy

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.

Top Solution Authors
Top Kudoed Authors