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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bolabuga
Helper V
Helper V

[ Retrieving the Last Date ]

Hello everyone,

I have the following scenario:

Revenue and Service tables don’t have a relationship (i don’t know how to handle it, it would be a many to many relationship based on client column)

Im creating a calculated column on revenue table, where I need to iterate the rows searching for the amount of services the client had over a period of time between -405 days and -40 days (no problem in here).

If the amount computed is >= 1, i need to retrieve the Last service date (by last i mean that: if i found 2 services date in the given period, date: 11/2/2017 and date: 25/7/2017, i want to retrieve 25/7/2017).

One problems is that "LASTDATE" can’t be used, as the service table has cases with same services in the same date for the same client, which I would be interested in any of the last repeated dates.

Using SUMX i can make it work right for cases where there’s only 1 service in the period consisted.

 

3.PNG

 

CALCULATED COLUMN LAST SERVICE  DATE = 
IF(
    COUNTROWS(
        FILTER(
            SERVICES;
            SERVICES[CLIENT] = REVENUE[CLIENT]
            && SERVICES[GROUP] = 1
            && ( SERVICES[DATE] >= REVENUE[DATE]) - 405 && SERVICES[DATE] <= REVENUE[DATE]) - 40 ))) >= 1;
SUMX(
        FILTER(
            SERVICES;
            SERVICES[CLIENT] = REVENUE[CLIENT]
            && SERVICES[GROUP] = 1
            && ( SERVICES[DATE] >= REVENUE[DATE]) - 405 && SERVICES[DATE] <= REVENUE[DATE]) - 40 ));
SERVICE[DATE])))
5 REPLIES 5
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @bolabuga,

 

Could you please provide detailed sample data? It would be helpful for us to better understand your scenario and test for you.

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yulgu-msft

 

Hi v-yulgu,

 

I did a test database and replicated the scenario that some insights would be great!!!

 

https://drive.google.com/open?id=0B8Aq8DhGApJqWDZlLTdQYnFibDQ

@v-yulgu-msft

I will try to mount a test base to replicate this.
bolabuga
Helper V
Helper V

It seens i manage to do the last part of the calculated column right, after reading some of the posts in the forum.

 

If any one can comment on this possible solution, i would be greatful, because there could be a better way to do this and im not seeing it. 

 

CALCULATE(
          MAX(SERVICES[DATE]);
          FILTER(
               SERVICES;
               SERVICES[CLIENT] = REVENUE[CLIENT]
               && SERVICES[GROUP] = 1
               && ( SERVICES[DATE] >= REVENUE[DATE] - 405 && SERVICES[DATE] <= REVENUE[DATE] - 40 )))))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.