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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Need a measure to return minimum dates for each rows

I am trying to return the first minimum date based on the group of -ve and -ve value for all the rows .

 

I need a measure to calculate the minimum date here because stock is calculated based on two different tables.

 

See the examples as below. 

 

datematerialstock
6/1/2022101-200
7/1/2022101-100
8/1/2022101100
9/1/2022101200
10/1/2022101-100
11/1/2022101-50

Expected Result :

datematerialstockresult
6/1/2022101-2006/1/2022
7/1/2022101-1006/1/2022
8/1/20221011008/1/2022
9/1/20221012008/1/2022
10/1/2022101-10010/1/2022
11/1/2022101-5010/1/2022

 

 

Can someone help me on this please?

@amitchandak @Ashish_Mathur 

 

1 ACCEPTED SOLUTION

Hi,

Thank you for your feedback.

Please check the attached file below.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

thanks again @Jihwan_Kim  have a good day 🙂

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I assumed the expected outcome shows minimum date for the groups of minus stocks or plus stocks.

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file, and each of them are numbered as a step to follow.

 

Untitled.png

 

step one plus minus change index: = 
VAR _currentstock =
    SUM ( Data[stock] )
VAR _currentdate =
    MAX ( Data[date] )
VAR _currentmaterial =
    MAX ( Data[material] )
VAR _previousdate =
    MAXX (
        FILTER (
            ALL ( Data ),
            Data[material] = _currentmaterial
                && Data[date] < _currentdate
        ),
        Data[date]
    )
VAR _previousstock =
    SUMX (
        FILTER (
            ALL ( Data ),
            Data[material] = _currentmaterial
                && Data[date] = _previousdate
        ),
        Data[stock]
    )
RETURN
IF( HASONEVALUE( Data[date]),
    IF ( _currentstock * _previousstock < 0, 1, 0 )
)

 

step two Group of change index: = 
IF (
    HASONEVALUE ( Data[date] ),
    SUMX (
        FILTER (
            ALL ( Data ),
            Data[material] = MAX ( Data[material] )
                && Data[date] <= MAX ( Data[date] )
        ),
        [step one plus minus change index:]
    )
)

 

step three group by step two: = 
VAR _currentgroup = [step two Group of change index:]
VAR _newtable =
    FILTER (
        ADDCOLUMNS (
            FILTER ( ALL ( Data ), Data[material] = MAX ( Data[material] ) ),
            "@group", [step two Group of change index:],
            "@stock", CALCULATE ( SUM ( Data[stock] ) )
        ),
        [@group] = _currentgroup
    )
VAR _findminstock =
    MAXX (
        GROUPBY ( _newtable, [@group], "@minstock", MINX ( CURRENTGROUP (), [@stock] ) ),
        [@minstock]
    )
RETURN
    IF (
        HASONEVALUE ( Data[date] ),
        MAXX ( FILTER ( _newtable, Data[stock] = _findminstock ), Data[date] )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Thank you @Jihwan_Kim  for your support. Yes you are absolutely correct.

 

I tried to replicate the same in my current report but unable to resolve it.

 

here is the file :

https://drive.google.com/file/d/1-HdbdhwZ_Voxb1-tjjsd8sTlKzolXLAC/view?usp=drivesdk

 

 

Hi,

Thank you for your feedback.

Please check the attached file below.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.