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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
amikm
Helper V
Helper V

issue with Selectcolumns and filter in DAX

I am trying to solve the below business logic using DAX:
I need a list of customer that has all
Nyka bags in last 18 mos
All orders in last 18 mos.
The date of last Nyka order
Who is the Sales rep on order
What is order status?

I have written a below DAX:

 

Table =
FILTER (
    SELECTCOLUMNS (
        FILTER ( Sales, Sales[Vendor_Name] = "NYKA" ),
        "CUSTOMER NO", Sales[CUSTOMER_NO],
        "Venodor Name", Sales[Vendor_Name],
        "Order Date", Sales[ORDER_DATE],
        "SALES REP", Sales[SALES_REP_ID],
        "ORDER STATUS", Sales[ORDER_STATUS]
    ),
    DATESINPERIOD (
        'Sales'[ORDER_DATE],
        MAX ( 'Sales'[ORDER_DATE] ),
        -18,
        MONTH
    )
)

 

looks like my order date is not filtering correctly also, I have a doubt Like I transform the business logic using correct or optimized dax or not?

 

Need help or suggestion

 

Thanks,

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @amikm 

 

You can use the following code to create a filtered table. 

Table 2 =
SELECTCOLUMNS (
    FILTER (
        Sales,
        Sales[Vendor_Name] = "NYKA"
            && Sales[ORDER_DATE] > EDATE ( MAX ( Sales[ORDER_DATE] ), -18 )
    ),
    "CUSTOMER NO", Sales[CUSTOMER_NO],
    "Venodor Name", Sales[Vendor_Name],
    "Order Date", Sales[ORDER_DATE],
    "SALES REP", Sales[SALES_REP_ID],
    "ORDER STATUS", Sales[ORDER_STATUS]
)

 

You can use EDATE to get the date that is the indicated number of months before or after the start date.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

2 REPLIES 2
v-jingzhang
Community Support
Community Support

Hi @amikm 

 

You can use the following code to create a filtered table. 

Table 2 =
SELECTCOLUMNS (
    FILTER (
        Sales,
        Sales[Vendor_Name] = "NYKA"
            && Sales[ORDER_DATE] > EDATE ( MAX ( Sales[ORDER_DATE] ), -18 )
    ),
    "CUSTOMER NO", Sales[CUSTOMER_NO],
    "Venodor Name", Sales[Vendor_Name],
    "Order Date", Sales[ORDER_DATE],
    "SALES REP", Sales[SALES_REP_ID],
    "ORDER STATUS", Sales[ORDER_STATUS]
)

 

You can use EDATE to get the date that is the indicated number of months before or after the start date.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

littlemojopuppy
Community Champion
Community Champion

@amikm do you have a date table and is it marked as one?    DATESINPERIOD is a time intelligence function which requires a date table

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.