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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
ankurdsharma
Frequent Visitor

DAX Help

Hi,

 

I am  new to Power BI and want to achieve  something which I have already done using sql. Following is the scenario:-

 

(1) I am having a table with Customer details and having columns like CustomerId, CustomerName, Sales, LastDayDate(which is having value of last day of the year) etc and if a customer is Active then it will have entry against the last day of every year and if not that means customer is not Active and will no have entry for that particular year's last date. Following is the sample data to refer:-

---------------------------------------------------------------

|  CustomerId  |  CustomerName  |  Sales  |  LastDayDate  |

---------------------------------------------------------------

|  1                   | ABC                     |  1000  |  2015-12-31    | 

---------------------------------------------------------------

|  2                   | XYZ                     |  2000  |  2015-12-31    | 

---------------------------------------------------------------

|  3                   | WIN                     |  1000  |  2015-12-31    | 

---------------------------------------------------------------

|  1                   | ABC                     |  1000  |  2016-12-31    | 

---------------------------------------------------------------

|  2                   | XYZ                     |  1000  |  2016-12-31    | 

---------------------------------------------------------------

 

(2) As per above table you can see that customer name 'WIN' (customerid-3) was active in 2015 but not in 2016.

(2) I want to achieve Calculate Sales value difference for the customer which were there in the '2015-12-31' but not in '2016-12-31'.

 

Kindly suggest.

 

Regards

Ankur

1 ACCEPTED SOLUTION

Hi,

 

You may refer to my solution in this PBI file.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @ankurdsharma ,

What is your desired result? Could you want to get the value about WIN?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Yes @v-danhe-msft, sum of sales for WIN customer.

 

Regards

Ankur

@ankurdsharma  Please add a new column in the source table to flag

 

Flag = 
VAR _MaxYear = YEAR(MAX(Test262NextCheck[LastDayDate]))
VAR _Lkp = LOOKUPVALUE(Test262NextCheck[CustID],Test262NextCheck[CustID],Test262NextCheck[CustID],Test262NextCheck[LastDayDate],DATEADD(Test262NextCheck[LastDayDate],1,YEAR))
RETURN IF(ISBLANK(_Lkp) && YEAR(Test262NextCheck[LastDayDate]) <> _MaxYear,"Yes","No")

image.png

 

Then Create a measure to sum the values with flag Yes.

 

Test262 = CALCULATE(SUM(Test262NextCheck[Sales]),Test262NextCheck[Flag]="Yes")

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Thanks @PattemManohar, I have another situation similar to same case as per below records

 

---------------------------------------------------------------

| CustomerId | CustomerName | Sales | LastDayDate |

---------------------------------------------------------------

| 1                 | ABC                   | 1000 | 2015-12-31 |

---------------------------------------------------------------

| 2                 | XYZ                   | 2000 | 2015-12-31 |

---------------------------------------------------------------

| 3                 | WIN                  | 1000 | 2015-12-31 |

---------------------------------------------------------------

| 1                 | ABC                  | 1000 | 2016-12-31 |

---------------------------------------------------------------

| 2                 | XYZ                  | 1000 | 2016-12-31 |

---------------------------------------------------------------

 

I want to find out the list of 'CustomerName' who were there as on date of '2015-12-31' but not as on date of '2016-12-31'. This thing I want to achieve on the basis of Slicer value. Suppose, in slicer I have choosen date of '2016-12-31' then logic should check for results for choosen date and previous year same date('2015-12-31') and It should give resullt of CustomerName who were their earlier but not now(slicer selected date). There can be n number or records in the table with multiple dates.

 

Please guide me.

Hi,

 

You may refer to my solution in this PBI file.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks you @Ashish_Mathur 

You are welcome


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey @Ashish_Mathur : one quick check, can we use/store that Churn customer id/id's value (which you shown in your example) like a filter in calculation at other Measures?

 

Regards

Ankur

Hi,

 

If you can show me the result you are expecting, i will be able to help you much better.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, 

 

Let me explaing it to you again. The sample which you have sent and is generating CustomerID which are churned as per attached screen. What I want is to store the results specially 'CustomerID' (these can be more than one) in separate table dynamically to use them again for another calculation. Let me know if make you to understand this.

I am talking about right side tableI am talking about right side table

Hi,

 

I do not know how to do that.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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