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

Get Sales for previous period for a specific Segment.

Hi,

 

I have a table with sales from a specific segment from a specifc date. I am trying to compute the sales from that specific segment for the previous period (the periods are random months). I have tried indexing, ranking and a bunch of other stuff but haven't gotten a solution yet. PLEASE HELP!?

CorneldaFaber_0-1651655440954.png

 

It should look like this...

DateNewCore Sort OrderTotalAdvances_CurrentTotalAdvances_Previous
2021/01/01 00:00a. Core and ThinR1 458 458 748 780 
2021/01/01 00:00b. CareR587 048 787 402 
2021/01/01 00:00c. Non-CoreR503 110 269 031 
2021/04/01 00:00a. Core and ThinR1 476 293 061 269R1 458 458 748 780
2021/04/01 00:00b. CareR594 140 554 312R587 048 787 402
2021/04/01 00:00c. Non-CoreR499 131 753 788R503 110 269 031
2021/06/01 00:00a. Core and ThinR1 492 034 668 624R1 476 293 061 269
2021/06/01 00:00b. CareR599 276 245 947R594 140 554 312
2021/06/01 00:00c. Non-CoreR470 619 814 057R499 131 753 788
2021/10/01 00:00a. Core and ThinR1 506 174 347 602R1 492 034 668 624
2021/10/01 00:00b. CareR614 210 342 518R599 276 245 947
2021/10/01 00:00c. Non-CoreR491 450 218 097R470 619 814 057
2021/12/01 00:00a. Core and ThinR1 550 784 408 578R1 506 174 347 602
2021/12/01 00:00b. CareR609 304 560 888R614 210 342 518
2021/12/01 00:00c. Non-CoreR486 522 888 568R491 450 218 097
1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @CorneldaFaber ,

 

According to my understanding, you want to get a value of the latest date before current date for each type.

Please try:

TotalAdvances_Previous =
VAR _lastDate =
    MAXX (
        FILTER (
            'Table',
            [Core Sort Order] = EARLIER ( 'Table'[Core Sort Order] )
                && [DateNew] < EARLIER ( 'Table'[DateNew] )
        ),
        [DateNew]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[TotalAdvances_Current] ),
        FILTER (
            'Table',
            [Core Sort Order] = EARLIER ( 'Table'[Core Sort Order] )
                && [DateNew] = _lastDate
        )
    )

Output:

Eyelyn9_0-1652059536859.png

Best Regards,
Eyelyn Qin
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
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=LOOKUPVALUE(Data[TotalAdvances_Current],Data[DateNew],CALCULATE(MAX(Data[DateNew]),FILTER(Data,Data[Core Sort Order]=EARLIER(Data[Core Sort Order])&&Data[DateNew]<EARLIER(Data[DateNew]))),Data[Core Sort Order],Data[Core Sort Order])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur 

 

Thanks for your post. Like I said above I figured out a way which is also working fine and that is very similar to your response. 

 

Thanks again. 

v-eqin-msft
Community Support
Community Support

Hi @CorneldaFaber ,

 

According to my understanding, you want to get a value of the latest date before current date for each type.

Please try:

TotalAdvances_Previous =
VAR _lastDate =
    MAXX (
        FILTER (
            'Table',
            [Core Sort Order] = EARLIER ( 'Table'[Core Sort Order] )
                && [DateNew] < EARLIER ( 'Table'[DateNew] )
        ),
        [DateNew]
    )
RETURN
    CALCULATE (
        MAX ( 'Table'[TotalAdvances_Current] ),
        FILTER (
            'Table',
            [Core Sort Order] = EARLIER ( 'Table'[Core Sort Order] )
                && [DateNew] = _lastDate
        )
    )

Output:

Eyelyn9_0-1652059536859.png

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

Hi @v-eqin-msft 

 

Thanks so much. This work. Before you posted I figured out the problem and did something similar. Thanks so much. 🙂

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.