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

Converting 3 steps table to only one table

Hi, I am new to DAX and I have an assignment which requires me to simplify all 3 steps table to only one table, preferably using CALCULATETABLE function.


Been trying this for almost 2 weeks now, still can't seem to get the idea.
Does anyone know how I can simplify these steps to only one table?

Thank you

 

Table 1:

forecasting_uoa_transactions_step1 = 
    FILTER (  
        SUMMARIZE ( 
            uoa_transactions_history, 
            uoa_transactions_history[Date], 
            uoa_transactions_history[Country], 
            "UoA", SUM(uoa_transactions_history[Total Changes])
        ),  
        DATEDIFF(uoa_transactions_history[Date],TODAY(),MONTH)<variable_uoa_per_cust_window[Variable_UoA_per_Cust_Window Value]+1
    )

Table 2:

forecasting_uoa_transactions_step2 = 
    SUMMARIZE ( 
        forecasting_uoa_transactions_step1, 
        forecasting_uoa_transactions_step1[Country],
        "UoA Per Customer Average", AVERAGE(forecasting_uoa_transactions_step1[UoA_per_Customer])
    )

Table 3:

forecasting_uoa_transactions_step3 = 
    SELECTCOLUMNS ( 
        customer_transactions_forecast,
        "Date", customer_transactions_forecast[YearMonth],
        "Country", customer_transactions_forecast[Country],
        "Customers", customer_transactions_forecast[Total Headcount]
    )

 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description and DAX formulas, I can roughly understand your requirement, I think you can use VAR to define the above two calculated tables as virtual tables to achieve the result in one single DAX formula, you can try to create a calculated table like this:

forecasting_uoa_transactions=
VAR  _step1 =
    FILTER ( 
        SUMMARIZE (
            uoa_transactions_history,
            uoa_transactions_history[Date],
            uoa_transactions_history[Country],
            "UoA", SUM(uoa_transactions_history[Total Changes])
        ), 
        DATEDIFF(uoa_transactions_history[Date],TODAY(),MONTH)<variable_uoa_per_cust_window[Variable_UoA_per_Cust_Window Value]+1
)
VAR  _step2 =
    SUMMARIZE (
        _step1,
        [Country],
        "UoA Per Customer Average", AVERAGE( [UoA_per_Customer])
    )
RETURN
SELECTCOLUMNS (
        _step2,
        "Date", [YearMonth],
        "Country", [Country],
        "Customers", [Total Headcount]
    )

And you can get what you want.

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert 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

2 REPLIES 2
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description and DAX formulas, I can roughly understand your requirement, I think you can use VAR to define the above two calculated tables as virtual tables to achieve the result in one single DAX formula, you can try to create a calculated table like this:

forecasting_uoa_transactions=
VAR  _step1 =
    FILTER ( 
        SUMMARIZE (
            uoa_transactions_history,
            uoa_transactions_history[Date],
            uoa_transactions_history[Country],
            "UoA", SUM(uoa_transactions_history[Total Changes])
        ), 
        DATEDIFF(uoa_transactions_history[Date],TODAY(),MONTH)<variable_uoa_per_cust_window[Variable_UoA_per_Cust_Window Value]+1
)
VAR  _step2 =
    SUMMARIZE (
        _step1,
        [Country],
        "UoA Per Customer Average", AVERAGE( [UoA_per_Customer])
    )
RETURN
SELECTCOLUMNS (
        _step2,
        "Date", [YearMonth],
        "Country", [Country],
        "Customers", [Total Headcount]
    )

And you can get what you want.

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

lbendlin
Super User
Super User

Table 3 seems to be unrelated to the first two steps.  Please validate your request.

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.

Top Solution Authors