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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

CALC Column to get next date from fact table?

Hi, I have a dimension table called Customers, and a fact table called Sales. These are in an SSAS Tabular model.

JD09631_1-1636544508662.png

 

I want to add a calculated column onto dbo customers called "next bike sale" which will show me the NEXT SalesDate from today per customer, for all productkeys of 2. So the output on the above would look like the below

JD09631_2-1636544555194.png



Can anyone help me achieve this, some of the solutions I found online suggested using the related function but it wont work (i think because customers table filters sales table)

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, if you want to get the second date after each grouping according to the customer field, you can refer to the following formula: first sort the dates according to the grouping. Then filter out the dates that meet the conditions:

rank_ = 
    RANKX (
        FILTER ( ALL ( Sales ), Sales[customer_key] = EARLIER ( Sales[customer_key] ) ),
        [sales_date],
        ,
        ASC,
Col_data = CALCULATE (
        MAX ( Sales[sales_date] ),
        FILTER (
            ALL ( Sales ),
            Sales[rank_] = 2
                && Sales[customer_key] = EARLIER ( Sales[customer_key] )
        )
    )

vhenrykmstf_0-1636961745480.png

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


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

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, if you want to get the second date after each grouping according to the customer field, you can refer to the following formula: first sort the dates according to the grouping. Then filter out the dates that meet the conditions:

rank_ = 
    RANKX (
        FILTER ( ALL ( Sales ), Sales[customer_key] = EARLIER ( Sales[customer_key] ) ),
        [sales_date],
        ,
        ASC,
Col_data = CALCULATE (
        MAX ( Sales[sales_date] ),
        FILTER (
            ALL ( Sales ),
            Sales[rank_] = 2
                && Sales[customer_key] = EARLIER ( Sales[customer_key] )
        )
    )

vhenrykmstf_0-1636961745480.png

If the problem is still not resolved, please point it out. Looking forward to your reply.


Best Regards,
Henry


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

Greg_Deckler
Community Champion
Community Champion

@Anonymous Seems like: Column = MINX(FILTER('FactTabe',[ProductKey]=2),[SalesDate])



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler .. this only seems to bring back the minimum date from the table and not the minimum date per customer?

Anonymous
Not applicable

nevermind I added && customer.customerkey = sales.customerkey to the filter and I think this has worked

@Anonymous Oh, I was assuming that the tables were related to one another on customerkey. Yes, if that is not the case then you will need that additional clause.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors