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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
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.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors