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
koorosh
Post Partisan
Post Partisan

table expression

Hi, I expected Customer and Purchase Date header for the following output. why I got Sales_Customer and Sales_Purchase Date?

 

koorosh_0-1634928692765.png

 

7 REPLIES 7
koorosh
Post Partisan
Post Partisan

Hi, Since the sales table has "customer" and "purchase date" columns, so the Lastpurchase variable that is the outcome of GroupBY should have common join columns to get correct output from NATURALLEFTJOIN as you see in the following!

koorosh_1-1635093633230.png

 

 

Hi @koorosh ,

 

Could you pls provide some dummy data with expected output for test?

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

Hi Kelly, I tried to break the final code in “Days since Last Purchase” into many steps. I expected in “Purchase step2” step, I got a table with “customer”, “Purchase date” and “Last purchase” columns. But as you see they are “sales_customer”, “sale_purchse date” and “Last purchase” instead.

https://drive.google.com/file/d/1Ily0fzWIu4MZTbfDQa-DfCrqyrc6m_fC/view?usp=sharing

 

Best regards

Koorosh

Hi  @koorosh ,

 

Should be something related to GENERATE Function,but I cant tell why.Maybe because that you have renamed the column names during generating.

But if you wanna get "Purchase_step2" with the headers you need,I have a simpler way:

First create a column in Sales as below:

Last Purchase Date =
CALCULATE (
    MAX ( 'sales'[Purchase Date] ),
    FILTER (
        'sales',
        'sales'[Customer] = EARLIER ( sales[Customer] )
            && 'sales'[Purchase Date] < EARLIER ( sales[Purchase Date] )
    )
)

Then create table "Purchase_step2" as following:

_Purchase_step2 =
VAR _tab =
    SELECTCOLUMNS (
        'sales',
        "Customer", [Customer],
        "Purchase Date", 'sales'[Purchase Date],
        "Last Purchase", 'sales'[Last Purchase Date]
    )
RETURN
    FILTER ( _tab, [Last Purchase] <> BLANK () )

And you will see:

vkellymsft_0-1635304163417.png

 

Check the .pbix attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

 

Hi Kelly, I am not sure that you noticed my point or not. I am saying in the final code in “Days since last purchase”, NATURALLEFTOUTERJOIN distinguished that Sales table and LastPrchase table (created by GROUPBY) have columns with identical header names (Customer column and Purchase Date column) , so that the output has customer and Purchase Date columns.

koorosh_0-1635447301527.png

But when I cut the last part of the code (cut NATURALLEFTOUTERJOIN) as you see in the “Purchase_step2” table , the output has not columns with header Customer and Purchase Date name. I did not change anything in GROUPBY function but the out put has columns  “sales_customer” and “sales_purchase date” not “Customer” and “Purchase Date” columns.

koorosh_2-1635447593624.png

 

Best Regards

Hi  @koorosh ,

 

I know,if I comment out part of your expression,I get the troubling result as you say:

vkellymsft_1-1635492680514.png

Based on my experience,if you use a table as a variable to get another table,it will be affected by context.

As we cant to query the internal mechanism of the function,I cant tell whether it is a bug,that's why I show you another method to get the result you need.

 

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

 

Hi @koorosh ,

 

It seems that the DAX function GROUP BY puts the table name as prefix in front of the corresponding GROUP BY columns.

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


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.