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
1125NEWBIUSER
Helper I
Helper I

Add filters to existing DAX Coding

Hello,

I am still new to Power BI and DAX Coding. I am working on creating columns to calculate our work in process. We do this by taking the cummulative orders and then subtract cummulative shipped products. Anyway, I have a DAX to do this but need to add two filters to the codes to specify orders and remove a sales type. The code I currently have is:

**bleep** WIP Order Today =
VAR LastVisibleDate =
    MAX ( 'Order/Wip Calculations'[Date] )
VAR FirstVisibleDate =
    MIN ( 'Order/Wip Calculations'[Date] )
VAR LastDateWithSales =
    CALCULATE (
        MAX ( 'Orders/WIP'[Order date] ),
        REMOVEFILTERS ('Orders/WIP')     )
VAR Result =
    IFFirstVisibleDate <= LastDateWithSales,
        CALCULATE (    Sum('Orders/WIP'[Quantity]),
            'Order/Wip Calculations'[Date] <= LastVisibleDate )    )
RETURN
    Result
 
I need to filter the [Quantity] field for the following lines:
'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard'
 
Everytime I try adding I get syntex errors and I am not really sure where I can add that it will work. Do I need to make a variable unit field for the filters and then add to general DAX?
 
Thanks, Chris
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@1125NEWBIUSER , 1 of the three ways

 

CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate , 'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard')


CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate , filter('Orders/WIP' ,'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard') )

 

 

CALCULATE (CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate) , filter('Orders/WIP' ,'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard') )

View solution in original post

2 REPLIES 2
1125NEWBIUSER
Helper I
Helper I

Thank you, this did the trick!

amitchandak
Super User
Super User

@1125NEWBIUSER , 1 of the three ways

 

CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate , 'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard')


CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate , filter('Orders/WIP' ,'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard') )

 

 

CALCULATE (CALCULATE ( Sum('Orders/WIP'[Quantity]),
'Order/Wip Calculations'[Date] <= LastVisibleDate) , filter('Orders/WIP' ,'Orders/WIP'[Invoiced] <>"Return" && 'Orders/WIP'[SalesTranType] = 'Standard') )

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