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
learningOh
Frequent Visitor

counting total distinct accounts based off selected period

Hi everyone,

 

learningOh_0-1692252049376.png


i like to count the total number of accounts whose lastinvoicedatefirstdate for each of the rows.

for example if i select selected period to be 12 months, then if the current row is 2023 january, i want it to count the total number of acounts found in 2022 january.

 

context

the idea is that if i am looking at 2023 january. then if an account whose last transaction with us is more than the selected period. which means that they have no activity at all from the last period to now, then we have deemed the account as a lost account.


i have this code but it keeps showing a blank in the table visual.

test3 =
var currentdates = LASTDATE('FACT'[key(calendarfirstdate)])
var lastpdate = dateadd(currentdates,-1*[Selected Period] ,month)
return

CALCULATE(DISTINCTCOUNT('FACT'[account num]),FILTER('FACT',
               'FACT'[lastinvoicedatefirstdate]= lastpdate))


--

i tried this code as well but it also shows blank

test3 = calculate(
DISTINCTCOUNT( 'FACT'[Account Num]), filter( 'FACT', 'FACT'[lastinvoicedatefirstdate] = DATEADD( LASTDATE('FACT'[key(calendarfirstdate)]), -1 * [Selected Period], month)

please help me modify the code or approach to achieve this
1 REPLY 1
amitchandak
Super User
Super User

@learningOh , Try like

 

test3 =
var currentdates = LASTDATE('FACT'[key(calendarfirstdate)])
var lastpdate = Date(Year(currentdates),month(currentdates)-1*[Selected Period] ,day(currentdates))
return

CALCULATE(DISTINCTCOUNT('FACT'[account num]),FILTER('FACT',
'FACT'[lastinvoicedatefirstdate]= lastpdate))

 

also refer

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee8...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.

Top Solution Authors
Top Kudoed Authors