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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
WarrenBarrell
Frequent Visitor

DAX to Count number of Companies Making a loss for either 2 or 3 months ago

Hello, 

 

I am trying to get a Card Visual based on the data table below. 

Assuming we are in the month of June 2022. 

1. No. of Companies with at least a loss 2 or 3 months ago (March or April)?

Expected Answer: 7

2. No. of Companies with losses in both 2 and 3 months ago (March and April)?

Expected Answer: 2

 

Your help would be highly appreciated. 

 

CompanyDateNet Profit/(Loss)

A31/01/2022($1,406.00)
B31/01/2022$13,309.00
31/01/2022$14,388.00
D31/01/2022$12,447.00
E31/01/2022$3,415.00
F31/01/2022($2,931.00)
G31/01/2022($39.00)
H31/01/2022$11,235.00
I31/01/2022($6,774.00)
J31/01/2022($3,757.00)
A28/02/2022$9,891.00
B28/02/2022($5,565.00)
28/02/2022$2,183.00
D28/02/2022$4,494.00
E28/02/2022$12,376.00
F28/02/2022$2,865.00
G28/02/2022($1,324.00)
H28/02/2022($2,504.00)
I28/02/2022$9,796.00
J28/02/2022$5,156.00
A31/03/2022($7,198.00)
B31/03/2022($2,044.00)
31/03/2022($7,462.00)
D31/03/2022$9,959.00
E31/03/2022($7,748.00)
F31/03/2022($277.00)
G31/03/2022$10,819.00
H31/03/2022$14,774.00
I31/03/2022$18,887.00
J31/03/2022($1,810.00)
A30/04/2022$12,778.00
B30/04/2022($1,777.00)
30/04/2022($6,900.00)
D30/04/2022$4,351.00
E30/04/2022$7,097.00
F30/04/2022$8,289.00
G30/04/2022$13,856.00
H30/04/2022($1,206.00)
I30/04/2022$19,995.00
J30/04/2022$14,876.00
A31/05/2022$8,356.00
B31/05/2022($6,637.00)
31/05/2022$1,022.00
D31/05/2022$16,946.00
E31/05/2022($4,525.00)
F31/05/2022$17,387.00
G31/05/2022$18,425.00
H31/05/2022$16,866.00
I31/05/2022$9,884.00
J31/05/2022($5,695.00)
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Losses both months =
VAR twoMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -2, MONTH ),
        'Table'[Net profit / loss] < 0
    )
VAR threeMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -3, MONTH ),
        'Table'[Net profit / loss] < 0
    )
RETURN
    COUNTROWS ( INTERSECT ( twoMonthsAgo, threeMonthsAgo ) )
Losses either month =
VAR twoMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -2, MONTH ),
        'Table'[Net profit / loss] < 0
    )
VAR threeMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -3, MONTH ),
        'Table'[Net profit / loss] < 0
    )
RETURN
    COUNTROWS ( DISTINCT ( UNION ( twoMonthsAgo, threeMonthsAgo ) ) )

Add the 'Date'[Date] column as a filter to the card visuals and use the relative date setting to be in the current month

View solution in original post

2 REPLIES 2
WarrenBarrell
Frequent Visitor

Thank you very much John. This worked perfectly!

johnt75
Super User
Super User

Losses both months =
VAR twoMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -2, MONTH ),
        'Table'[Net profit / loss] < 0
    )
VAR threeMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -3, MONTH ),
        'Table'[Net profit / loss] < 0
    )
RETURN
    COUNTROWS ( INTERSECT ( twoMonthsAgo, threeMonthsAgo ) )
Losses either month =
VAR twoMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -2, MONTH ),
        'Table'[Net profit / loss] < 0
    )
VAR threeMonthsAgo =
    CALCULATETABLE (
        VALUES ( 'Table'[Company] ),
        PARALLELPERIOD ( 'Date'[Date], -3, MONTH ),
        'Table'[Net profit / loss] < 0
    )
RETURN
    COUNTROWS ( DISTINCT ( UNION ( twoMonthsAgo, threeMonthsAgo ) ) )

Add the 'Date'[Date] column as a filter to the card visuals and use the relative date setting to be in the current month

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.