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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Lucy64
Helper III
Helper III

Dax Calculation of January total

I need help with the calculation in Dax:

 

Below is the graph I need and the line is giving the correct results.  The number "850" is the total for January and I need to put in a formula to calculate month 1 instead. So the formula will work when I select a different year.  Thanks.

 

Calc1.PNG

1 ACCEPTED SOLUTION
v-micsh-msft
Employee
Employee

Hi Lucy64,

 

What is your current situation?

To use measure to help calculate the first month value of each year, we need add filter in the measure.

In addition to the month value, we also need to filter the year within Measure.

Follow the steps below:

  1. If you don’t have a date table, create one, using the New table in Power BI desktop Data View, with the formula below:Then under relationship View, link this datetable with your data table, here we use sheet1 for example. 
    Datetable = CALENDAR(min(Sheet1[Date]),max(Sheet1[Date]))
  2. In the newly created datetable, create a year column, with the formula below: 
    Year = year('Datetable'[Date])
  3. Under the datetable, create a new measure with the formula below, we will use this measure to filter the years:
    yearC = IF( HASONEVALUE( 'Datetable'[Year] ), CALCULATE( VALUES( 'Datetable'[Year])))
  4. Under your Data table, where you have [CalTotalIOT] calculated, create another measure to calculate the first month value, with the measure below:
    FirstmonthValue = calculate([CalTotalIOT], filter(ALLSELECTED(Sheet1),and(month(Sheet1[Date])=1, year(Sheet1[Date])=[yearC])))
  5. Create the Precent measure with the measure below:
    Precent = ([Month1sales2]-[Measure])/[Month1sales2]
  6. After that, when select the value in the Column and line chart, choose the date from the datetable, others from your data table. See my result:

1.PNG

Post back if any further assistance needed.

Regards

View solution in original post

3 REPLIES 3
v-micsh-msft
Employee
Employee

Hi Lucy64,

 

What is your current situation?

To use measure to help calculate the first month value of each year, we need add filter in the measure.

In addition to the month value, we also need to filter the year within Measure.

Follow the steps below:

  1. If you don’t have a date table, create one, using the New table in Power BI desktop Data View, with the formula below:Then under relationship View, link this datetable with your data table, here we use sheet1 for example. 
    Datetable = CALENDAR(min(Sheet1[Date]),max(Sheet1[Date]))
  2. In the newly created datetable, create a year column, with the formula below: 
    Year = year('Datetable'[Date])
  3. Under the datetable, create a new measure with the formula below, we will use this measure to filter the years:
    yearC = IF( HASONEVALUE( 'Datetable'[Year] ), CALCULATE( VALUES( 'Datetable'[Year])))
  4. Under your Data table, where you have [CalTotalIOT] calculated, create another measure to calculate the first month value, with the measure below:
    FirstmonthValue = calculate([CalTotalIOT], filter(ALLSELECTED(Sheet1),and(month(Sheet1[Date])=1, year(Sheet1[Date])=[yearC])))
  5. Create the Precent measure with the measure below:
    Precent = ([Month1sales2]-[Measure])/[Month1sales2]
  6. After that, when select the value in the Column and line chart, choose the date from the datetable, others from your data table. See my result:

1.PNG

Post back if any further assistance needed.

Regards

Michael, thank you very much.  I followed your instructions and it works perfect!  I really love power BI just wish I could get my head around the DAX language.  I need to look for an online course or some good books to read.

 

Thanks again.

Greg_Deckler
Super User
Super User

In general, something like:

 

MyMeasure = CALCULATE([CalTotalIOT],[Month] = 1)

Follow on LinkedIn
@ 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...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.