Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
New_be
Helper V
Helper V

To get the date of production on when it achieves sqft planned

Hi, I have an issue to create things that I wanted in the query editor (M query). I wanted to get the date of production when that orderID per process achieve sqft planned. I tried few things, but it didn’t work. I attached an excel file of the detail (small and simple details) that I wanted for your reference. Thank you for the help in advance.

2 ACCEPTED SOLUTIONS

Hi @New_be 

Doing it in Power Query would be slow as it would involve grouping rows and scaning a table.  DAX is more optimized for that.  As measures, create these:

Percent 95 = 570 //can be an expression like DIVIDE ( numerator, denominator )

Date01 = 
VAR _TBL =
    ADDCOLUMNS(
        SUMMARIZE('Table', 'Table'[OrderID], 'Table'[ProcessID], 'Table'[Date]),
        "@Cumulative",
        CALCULATE(
            SUM('Table'[SQFT]),
            FILTER(
                ALLEXCEPT('Table', 'Table'[OrderID], 'Table'[ProcessID]),
                'Table'[Date] <= EARLIER('Table'[Date])
            )
        )
    )
VAR _Filtered =
    FILTER(_TBL, [@Cumulative] >= [Percent 95])
VAR _MinDate =
    MINX(_Filtered, [Date])
RETURN
_MinDate


Date02 = 
VAR _Date =
    CALCULATE (
        [Date01],
        ALLEXCEPT ( 'Table', 'Table'[OrderID], 'Table'[ProcessID] )
    )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[Date] ) = _Date, _Date )

 

As a calculated table, make sure [Percent 95] measure exists and then create this:

CalcTbl = 
VAR _TBL =
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[OrderID], 'Table'[ProcessID], 'Table'[Date] ),
        "@Cumulative",
            CALCULATE (
                SUM ( 'Table'[SQFT] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[OrderID], 'Table'[ProcessID] ),
                    'Table'[Date] <= EARLIER ( 'Table'[Date] )
                )
            )
    )
VAR _Filtered =
    FILTER ( _TBL, [@Cumulative] >= [Percent 95] )
RETURN
    GROUPBY (
        _Filtered,
        'Table'[OrderID],
        'Table'[ProcessID],
        "Date", MINX ( CURRENTGROUP (), [Date] )
    )

 

danextian_0-1732179384142.png

 

danextian_1-1732179398976.png

Please see attached sample pbix

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Anonymous
Not applicable

Hi @New_be ,

 

According to your sample, I think there are two tables in your data model: PlannedTable and OutputTable.

Add a [95% from SQFT_PLANNED] in PlannedTable:

vrzhoumsft_0-1732264618108.png

OutputTable:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjcwtFDSUXLz9AOShgb6hqb6RgZGJiCOobFSrA4WFWYwFSam5thVmMNUGBsgKwgI8ocqsIApMDICGhELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OrderID = _t, ProcessID = _t, Date = _t, SQFT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"OrderID", Int64.Type}, {"ProcessID", type text}, {"Date", type date}, {"SQFT", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"OrderID"}, PlannedTable, {"OrderID"}, "PlannedTable", JoinKind.LeftOuter),
    #"Expanded PlannedTable" = Table.ExpandTableColumn(#"Merged Queries", "PlannedTable", {"95% from SQFT_PLANNED"}, {"95% from SQFT_PLANNED"}),
    #"Added CumulativeSqft" = Table.AddColumn(#"Expanded PlannedTable", "CumulativeSqft", each let 
    _OrderID = [OrderID],
    _Date = [Date]
    in
    List.Sum(
    Table.SelectRows(#"Expanded PlannedTable", each [OrderID] = _OrderID and [Date]<=_Date )[SQFT])),
    
    #"Added DateAchieveTarget" = Table.AddColumn(#"Added CumulativeSqft", "DateAchieveTarget", each let 
    _OrderID = [OrderID]
    in
    if [CumulativeSqft] = 
    List.Min(Table.SelectRows(#"Added CumulativeSqft", each [OrderID] = _OrderID and [CumulativeSqft]>=[#"95% from SQFT_PLANNED"])[CumulativeSqft])
    then [Date] else null)
in
    #"Added DateAchieveTarget"

Result is as below.

vrzhoumsft_1-1732264647081.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

4 REPLIES 4
New_be
Helper V
Helper V

Thank you guys! it helps alot + I learn new thing. Thanks again. 🙂

New_be
Helper V
Helper V

I forgot to attached link in the request. So below is the link:
Pbix example 

Anonymous
Not applicable

Hi @New_be ,

 

According to your sample, I think there are two tables in your data model: PlannedTable and OutputTable.

Add a [95% from SQFT_PLANNED] in PlannedTable:

vrzhoumsft_0-1732264618108.png

OutputTable:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjcwtFDSUXLz9AOShgb6hqb6RgZGJiCOobFSrA4WFWYwFSam5thVmMNUGBsgKwgI8ocqsIApMDICGhELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OrderID = _t, ProcessID = _t, Date = _t, SQFT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"OrderID", Int64.Type}, {"ProcessID", type text}, {"Date", type date}, {"SQFT", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"OrderID"}, PlannedTable, {"OrderID"}, "PlannedTable", JoinKind.LeftOuter),
    #"Expanded PlannedTable" = Table.ExpandTableColumn(#"Merged Queries", "PlannedTable", {"95% from SQFT_PLANNED"}, {"95% from SQFT_PLANNED"}),
    #"Added CumulativeSqft" = Table.AddColumn(#"Expanded PlannedTable", "CumulativeSqft", each let 
    _OrderID = [OrderID],
    _Date = [Date]
    in
    List.Sum(
    Table.SelectRows(#"Expanded PlannedTable", each [OrderID] = _OrderID and [Date]<=_Date )[SQFT])),
    
    #"Added DateAchieveTarget" = Table.AddColumn(#"Added CumulativeSqft", "DateAchieveTarget", each let 
    _OrderID = [OrderID]
    in
    if [CumulativeSqft] = 
    List.Min(Table.SelectRows(#"Added CumulativeSqft", each [OrderID] = _OrderID and [CumulativeSqft]>=[#"95% from SQFT_PLANNED"])[CumulativeSqft])
    then [Date] else null)
in
    #"Added DateAchieveTarget"

Result is as below.

vrzhoumsft_1-1732264647081.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.

 

Hi @New_be 

Doing it in Power Query would be slow as it would involve grouping rows and scaning a table.  DAX is more optimized for that.  As measures, create these:

Percent 95 = 570 //can be an expression like DIVIDE ( numerator, denominator )

Date01 = 
VAR _TBL =
    ADDCOLUMNS(
        SUMMARIZE('Table', 'Table'[OrderID], 'Table'[ProcessID], 'Table'[Date]),
        "@Cumulative",
        CALCULATE(
            SUM('Table'[SQFT]),
            FILTER(
                ALLEXCEPT('Table', 'Table'[OrderID], 'Table'[ProcessID]),
                'Table'[Date] <= EARLIER('Table'[Date])
            )
        )
    )
VAR _Filtered =
    FILTER(_TBL, [@Cumulative] >= [Percent 95])
VAR _MinDate =
    MINX(_Filtered, [Date])
RETURN
_MinDate


Date02 = 
VAR _Date =
    CALCULATE (
        [Date01],
        ALLEXCEPT ( 'Table', 'Table'[OrderID], 'Table'[ProcessID] )
    )
RETURN
    IF ( SELECTEDVALUE ( 'Table'[Date] ) = _Date, _Date )

 

As a calculated table, make sure [Percent 95] measure exists and then create this:

CalcTbl = 
VAR _TBL =
    ADDCOLUMNS (
        SUMMARIZE ( 'Table', 'Table'[OrderID], 'Table'[ProcessID], 'Table'[Date] ),
        "@Cumulative",
            CALCULATE (
                SUM ( 'Table'[SQFT] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[OrderID], 'Table'[ProcessID] ),
                    'Table'[Date] <= EARLIER ( 'Table'[Date] )
                )
            )
    )
VAR _Filtered =
    FILTER ( _TBL, [@Cumulative] >= [Percent 95] )
RETURN
    GROUPBY (
        _Filtered,
        'Table'[OrderID],
        'Table'[ProcessID],
        "Date", MINX ( CURRENTGROUP (), [Date] )
    )

 

danextian_0-1732179384142.png

 

danextian_1-1732179398976.png

Please see attached sample pbix

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.