DAX: Count where row value equals filter context

greenguy2012

New Member
Joined
Aug 19, 2018
Messages
4
[FONT=&quot]Hey there,[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]New to DAX so any help is appreciated. My goal is to understand how many customers cancel in a given sold date. Basically how many items did we sell in a given time period vs how many cancelled in that same period. [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]What I'm trying to do is count the number of rows where [Cancel Date] column values equal the Pivot Table Row Context Date [Sold Date] grouped by Month. Ex Grouped by Jan Sold Month, 10 cancelled in same Jan period[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Needed Pivot Table output:[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Sold Month. | Cancel Count[/FONT]
[FONT=&quot]- Jan. | 10[/FONT]
[FONT=&quot]- Feb | 15[/FONT]
[FONT=&quot]- Mar | 20[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Hopefully thats clear. Thanks in advance for your help![/FONT]
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Here is the formula I think it would be but it doesn't work

=CALCULATE([Count Cancelled],filter(all('Table'),[Cancel Month]=[Sold Month** this is the pivot table row sold month])
 
Upvote 0
If you create an inactive relationship between Dates[Date] and Sales[Cancel Date] and an active relationship between Dates[Date] and Sales[Sold Date] then

Sales in Period is simply

=<br><span class="Keyword" style="color:#0070FF">COUNTROWS</span><span class="Parenthesis" style="color:#969696"> (</span> Sales <span class="Parenthesis" style="color:#969696">)</span><br>


Cancel in Period is:

=<br><span class="Keyword" style="color:#0070FF">SUMX</span><span class="Parenthesis" style="color:#969696"> (</span><br><span class="indent4">    </span><span class="Keyword" style="color:#0070FF">SUMMARIZE</span><span class="Parenthesis" style="color:#969696"> (</span> Sales, Dates[Month], Dates[Year] <span class="Parenthesis" style="color:#969696">)</span>,<br><span class="indent4">    </span><span class="Keyword" style="color:#0070FF">CALCULATE</span><span class="Parenthesis" style="color:#969696"> (</span><br><span class="indent8">        </span><span class="Keyword" style="color:#0070FF">COUNTROWS</span><span class="Parenthesis" style="color:#969696"> (</span> Sales <span class="Parenthesis" style="color:#969696">)</span>,<br><span class="indent8">        </span><span class="Keyword" style="color:#0070FF">USERELATIONSHIP</span><span class="Parenthesis" style="color:#969696"> (</span> Sales[Cancel Date], Dates[Date] <span class="Parenthesis" style="color:#969696">)</span><br><span class="indent4">    </span><span class="Parenthesis" style="color:#969696">)</span><br><span class="Parenthesis" style="color:#969696">)</span><br>

Notice that SUMMARIZE uses the active relationship whereas the measure inside SUMX uses the inactive relationship. This allows you to not display data for those months where you have cancellations but not sales.



NweW5Jm.png


0MdJFbb.png
 
Upvote 0
If you create an inactive relationship between Dates[Date] and Sales[Cancel Date] and an active relationship between Dates[Date] and Sales[Sold Date] then

Sales in Period is simply

=
COUNTROWS ( Sales )



Cancel in Period is:

=
SUMX (
SUMMARIZE ( Sales, Dates[Month], Dates[Year] ),
CALCULATE (
COUNTROWS ( Sales ),
USERELATIONSHIP ( Sales[Cancel Date], Dates[Date] )
)
)


Notice that SUMMARIZE uses the active relationship whereas the measure inside SUMX uses the inactive relationship. This allows you to not display data for those months where you have cancellations but not sales.



NweW5Jm.png


0MdJFbb.png

Thanks so much, this achieves a static version of what I am looking for.

If I wanted to drag say "Product Type" into the Pivot as a Column header, it looks like this doesn't work. Is there a way for the Summarize section to be dynamic based on what filter context is in the pivot table?
 
Upvote 0
Thanks so much, this achieves a static version of what I am looking for.

If I wanted to drag say "Product Type" into the Pivot as a Column header, it looks like this doesn't work. Is there a way for the Summarize section to be dynamic based on what filter context is in the pivot table?

Hello, is the product ID in the 'Sales' table? do you have a 'Products' dimension table? Could you share a more representative table ?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top