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
CarlsBerg999
Helper V
Helper V

applying date filters to a calculated table (subset)

Hi,

 

My table looks like the following:

Transaction ID Account ID Attribute mod. Value € Value
70345 320664 Lost 4 200,00 25/08/2022
70345 320664 New  4 200,00 05/05/2021
70345 320664 Sourced 4 200,00  
80142 340033 Lost 5 400,00 15/02/2021
80142 340033 Conference 5 400,00 19/08/2020
80142 340033 New  5 400,00 01/01/2020
80142 340033 Sourced 5 400,00  
91100 320664 Lost 4 200,00 22/03/2021
91100 320664 New 4 200,00 05/01/2021
91100 320664 Sourced 4 200,00  

 

What i need to do, is to count how many Transaction ID's have been lost during a selected period. However, the transaction should not have specfic items in the Attribute Mod. -column. Assuming the selected date is 31.12.2022 the table above should only return transaction ID 70345 because it is lost during 2022 but it does not have a Conference, Called or Sourced -attributes associated with it. 

 

My Measure is presented below. My problem is with the dates. The variables return correct dates but the RETURN -part of the measure ignores the date restrictions. The other restrictions work fine. 

How do i apply a filter to the measure below, so that the Lost date must be between 1.1.2022 and 31.12.2022? 

 

 

VAR Selected_Date_less_365 = [Funnel: Selected Date (EOMONTH)]-365 //This takes 31.12.2022 - 365
VAR Selected_Date1 = [Funnel: Selected Date (EOMONTH)] // is 31.12.2022

RETURN
COUNTROWS(
    CALCULATETABLE(
        FILTER(
            CALCULATETABLE(VALUES(Table[Transaction ID])),
                    ISEMPTY(CALCULATETABLE('Table',
                    'Table'[Attribute mod.]="Conference"))
                &&
                    ISEMPTY(CALCULATETABLE('Table',
                    'Table'[Attribute mod.]="Sourced"))
                &&
                    ISEMPTY(CALCULATETABLE('Table',
                    'Table'[Attribute mod.]="Called"))
                &&
                    NOT ISEMPTY(CALCULATETABLE('Table',
                    'Table'[Attribute mod.]="Lost"))
                &&
                    NOT ISEMPTY(CALCULATETABLE('Table',
                    Table[Value]>Selected_Date_less_365,
                    Table[Value]<=Selected_Date1,
                    FILTER(Table,Table[Earliest Signed Contract]>Selected_Date_less_365),
                    FILTER(Table,Table[Earliest Signed Contract]<=Selected_Date1)))),
        CROSSFILTER(DateTable[Date],'Related_Table'[End Date],none)))

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@CarlsBerg999 I would do it this way, PBIX is attached below signature.

Measure = 
    VAR __Date = MAX('Dates'[Date])
    VAR __BeginDate = DATE(YEAR(__Date),1,1)
    VAR __Table = FILTER(ALL('Table'),[Value]>=__BeginDate && [Value]<=__Date)
    VAR __LostIDs = DISTINCT(SELECTCOLUMNS(FILTER(__Table,[Attribute mod.] = "Lost"),"__TransactionID",[Transaction ID]))
    VAR __OtherIDs = DISTINCT(SELECTCOLUMNS(FILTER(__Table,[Attribute mod.] = "Conference" || [Attribute mod.] = "Sourced" || [Attribute mod.] = "Called"),"__TransactionID",[Transaction ID]))
    VAR __Result = COUNTROWS(EXCEPT(__LostIDs, __otherIDs))
RETURN
    __Result

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@CarlsBerg999 I would do it this way, PBIX is attached below signature.

Measure = 
    VAR __Date = MAX('Dates'[Date])
    VAR __BeginDate = DATE(YEAR(__Date),1,1)
    VAR __Table = FILTER(ALL('Table'),[Value]>=__BeginDate && [Value]<=__Date)
    VAR __LostIDs = DISTINCT(SELECTCOLUMNS(FILTER(__Table,[Attribute mod.] = "Lost"),"__TransactionID",[Transaction ID]))
    VAR __OtherIDs = DISTINCT(SELECTCOLUMNS(FILTER(__Table,[Attribute mod.] = "Conference" || [Attribute mod.] = "Sourced" || [Attribute mod.] = "Called"),"__TransactionID",[Transaction ID]))
    VAR __Result = COUNTROWS(EXCEPT(__LostIDs, __otherIDs))
RETURN
    __Result

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,

 

Thank you! This is very close, but this loses one important functionality, unless you can solve it: Can you figure out a way in which we can add multiple conditions to left table (Lost IDs)? In other words, I need to also calculate how many transactions were Lost despite being Called. 

As count rows that: 

[Attribute mod.] = "Lost"

&&

[Attribute mod.] = "Called"


But exclude the others listed in left table (Conference, Sourced). Because the data is in the same column, i can't just add a second condition to the filter

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.