Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to filter using DAX in PowerPivot 2013

Posted on 2013-11-04
4
Medium Priority
?
679 Views
Last Modified: 2013-11-05
I'm working with PowerPivot in Excel 2013. Data is loaded from SQL Server 2012.

I have a data table named Results (ResultID int, OrderOpenTime datetime, AccountBalance decimal, AccountEquity decimal, DateKey date) and a lookup table DimDates with various time dimensions. The Results table is updated about every 5 minutes with the latest account and equity number which is good for trend pivots, but I have a problem with grouping to show results.

I've added measures to the Results table called FirstRowDateTime and LastRowDateTime that correctly gives me the first and last row for the selected time period, but I'm unable to use them for filtering.

By my limited understanding
:=CALCULATE(SUM([AccountBalance]);FILTER(Results; Results[OrderOpenTime]=[FirstRowDateTime]))
should calculate the sum of only one row (the first one in the chosen time period of the pivot table), but instead I get the sum of all [AccountBalance] as if the FILTER statement wasn't even there.

What am I missing? I've included a spreadsheet with sample data.

TIA!
Dennis
DAX-problem.xlsx
0
Comment
Question by:Dennis_Gundersen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 1500 total points
ID: 39624508
I think all you need is:

=SUMX(TOPN(1,Results, Results[OrderOpenTime],1),[AccountBalance])
0
 

Author Comment

by:Dennis_Gundersen
ID: 39624603
Thank you, that's very close. When I replace Results[OrderOpenTime] with my measure for the same thing I get the formula
=SUMX(TOPN(1;Results;[FirstRowDateTime];1);[AccountBalance])
which does give me the incoming balance, but I'm not quite sure the formula works the right way since when I replace "first row" with "last row" as in
=SUMX(TOPN(1;Results;[LastRowDateTime];1);[AccountBalance])
I get the same result.

The first row should return $2000.00, but the second formula should return $2018.40.

By changing the ordering direction to 0 for the second formula, I fortunately get the value I need, so I can finally move on using this solution, but it still looks to me like the First/LastRowDateTime measure is more or less ignored as a filter, which I fail to understand.

Re
D

Update: Never mind, I get it now. SUMX is an iterator so it looks through all the rows. I probably shouldn't use an iterator on a data table, but I'll take it. Thanks!
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39624715
You don't need your First/Last measures at all. For the FirstBalance, you use:

=SUMX(TOPN(1;Results;Results[OrderOpenTime];1);[AccountBalance])
and for the last balance you use:
=SUMX(TOPN(1;Results;Results[OrderOpenTime];0);[AccountBalance])
0
 

Author Comment

by:Dennis_Gundersen
ID: 39624729
Yes, I just posted an update to my reply. Took me awhile to remember the difference between SUM and SUMX. Thank you very much, I've been stuck on this problem for 2 weeks.

Re
Dennis
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question