• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

How to Create Dax(Measure) with condition|Power Pivot|Excel Forum|My Online Training Hub

You are here: Home / How to Create Dax(Measure) with condition|Power Pivot|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower PivotHow to Create Dax(Measure) with con…
sp_PrintTopic sp_TopicIcon
How to Create Dax(Measure) with condition
Avatar
Dalasamoud Khamphadith

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2020
sp_UserOfflineSmall Offline
1
January 13, 2020 - 6:03 pm
sp_Permalink sp_Print

Dear All,

As me try to create some DAX(Measure) in Power Pivot with condition as below but facing error, kindly help/guide how to create DAX in Pivot,

Let Say: DISTINCTCOUNT with condition(mean need only data with status "On" or "Off"

Here the mean point in my demo 

1. DISTINCTCOUNT for the Shop only Status "On"
2. Total Sale for the Shop only status "On"
3. Total Avg Sales only status "On"
4. DISTINCTCOUNT for the Shop Total Sales >= Total Avg only Status "On" 

Here link for demo file or attached below 
https://drive.google.com/file/.....sp=sharing

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
January 14, 2020 - 8:08 pm
sp_Permalink sp_Print

Hi Dalasamoud,

Try:

Total Shop:=CALCULATE(DISTINCTCOUNT(tbtesting[Shop ID]),tbtesting[Status]="On")

For SUM, use a similar measure (you already have that):

Total SalesON:=CALCULATE(SUM(tbtesting[Total_Sales]),tbtesting[Status]="On")

AVG:

Total AVGwith Status On:=CALCULATE(AVERAGE(tbtesting[Total_Sales]),tbtesting[Status]="On")

The average is 191.67, not 230 as in your expected results.

sp_AnswersTopicAnswer
Answers Post
Avatar
Dalasamoud Khamphadith

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2020
sp_UserOfflineSmall Offline
3
January 15, 2020 - 2:28 pm
sp_Permalink sp_Print

Dear Catalin Bombea,

Thank you (^_^) for your kindness, the Measure is working fine,

There's a concern how to find DISTINCTCOUNT for the Shop as below

1. How many Shop(DISTINCTCOUNT) Total Sales(Status="On") >= Total AVG(Status="On")

Let say: As my demo excel below

Shop ID Shop_Name Total_Sales Month Status
001 Mr Daovone $100.00 Jan On
002 Mr Keo $150.00 Jan On
003 Mrs khunjai $90.00 Jan On
004 Miss keotar $300.00 Jan On
005 Mr Soudjai $210.00 Jan On
001 Mr Daovone $300.00 Feb On

 

Total Sales: 1,150.00 $

Total AVG: 191.67 $

Shop(DISTINCTCOUNT) Total Sales(Status="On") >= Total AVG(Status="On") = 3 as below Shop Id

1. 001 Total Sales:400$ 

2. 004 Total Sales:300$

3. 005 Total Sales:210$

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
January 16, 2020 - 5:34 pm
sp_Permalink sp_Print

If you have those 3 measures, all you have to do is to use them:

DistinctON:=CALCULATE(DISTINCTCOUNT(tbtesting[Shop ID]),tbtesting[Status]="On")

TotalSalesON:=CALCULATE(SUM(tbtesting[Total_Sales]),tbtesting[Status]="On")

AvgON:=CALCULATE(AVERAGE(tbtesting[Total_Sales]),tbtesting[Status]="On",ALL(tbtesting))

YourAnswer:=CALCULATE([DistinctON],Filter(tbtesting,[TotalSalesON]/[DistinctON]>=[AvgON]))

Avatar
Dalasamoud Khamphadith

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2020
sp_UserOfflineSmall Offline
5
January 16, 2020 - 7:24 pm
sp_Permalink sp_Print

Dear Catalin Bombea,

Big thank you for your help(^_^), all your help measure is working fine.

As me try and checking result incorrect, i think my question not clear  

DaxTesting-1.pngImage Enlarger

Let say: As above Pic for Jan 

          => There're 5 shops Id (001, 002, 003, 004, 005)

         => Total Sales: 850$

         => Avg: 170$ 

 In Jan there're 2 Shops Total Sales >= 170$ is (004:300$ and 005:210$)

(Mean in 5 Shops how many shop Total sales >=170$ as data of Jan)

sp_PlupAttachments Attachments
  • sp_PlupImage DaxTesting-1.png (49 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
January 16, 2020 - 9:30 pm
sp_Permalink sp_Print

You keep changing the pivot context, you had before shop ID, now you have month. Many times, if you change the pivot context, there is a good chance for a measure to stop working as expected, you have to adjust it.

Also, you are not using the AvgON measure I sent, yours is not accurate. If you want AVG measure to be aware of pivot context (to change the average on each row of the pivot), you can remove ALL(tbtesting) from the measure, otherwise the average will be across the entire table, ignoring row context.

Avatar
Dalasamoud Khamphadith

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
January 13, 2020
sp_UserOfflineSmall Offline
7
January 17, 2020 - 12:22 pm
sp_Permalink sp_Print

Dear Catalin Bombea,

Big thank you sir, now i got the point and clear the top pic 

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Philip Treacy, Riny van Eekelen, Alexandra Radu, Monique Roussouw, michael serna
Guest(s) 9
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
Forum Stats:
Groups: 3
Forums: 24
Topics: 6215
Posts: 27248

 

Member Stats:
Guest Posters: 49
Members: 31897
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.