Wednesday, September 5, 2012

Power BI: DAX: Using Multi Select Slicer show different charts for each selected item.


1. AllSelection = IF(NOT(ISFILTERED(PLDeviceID[VideoSportClean])),"All",
CONCATENATEX(ALLSELECTED(PLDeviceID[VideoSportClean]),PLDeviceID[VideoSportClean],","))&","

2. AllSelectionCount = LEN([AllSelection])-LEN(SUBSTITUTE([AllSelection],",",""))

3. FirstMeasure = CALCULATE(SUM(PLDeviceID[LiveStreamStartsEvent19]),FILTER(PLDeviceID,PLDeviceID[LiveStreamStartsEvent19]>0),FILTER(ALLSELECTED(PLDeviceID),PLDeviceID[VideoSportClean] =[FirstSelection]))

4. FirstSelection = LEFT([AllSelection],SEARCH(",",[AllSelection])-1)

5. SecondMeasure = CALCULATE(SUM(PLDeviceID[LiveStreamStartsEvent19]),FILTER(PLDeviceID,PLDeviceID[LiveStreamStartsEvent19]>0),FILTER(ALLSELECTED(PLDeviceID),PLDeviceID[VideoSportClean] =[SecondSelection]))

6. SecondSelection = MID([AllSelection],SEARCH(",",[AllSelection])+1,SEARCH(",",[AllSelection],SEARCH(",",[AllSelection])))

Running Total 
Last Available Value


DAX query examples: DAX Running Total:

DAX Running Total:

git clone git@gist.github.com:92e8e3b7a1a212549af4.git gist-92e8e3b7

Tuesday, September 4, 2012

How to find if data has been loaded into database


Here is a simple way to find if the data has been loaded into database without checking every table one after another. This returns a single statement which has count of all the records in all the tables. You can also provide the table schema to narrow your query process.


DECLARE @sql VARCHAR(max), @tableSchema VARCHAR(5)
SET @sql = ''
SET @tableSchema = 'DW'
SELECT @sql = @sql + 'SELECT COUNT(*) as Count,'''+TABLE_NAME+''' AS table_Name FROM '+TABLE_SCHEMA+'.' +TABLE_NAME +' UNION '
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = @tableSchema
SET @sql = LEFT(@sql,LEN(@sql)-LEN('union'))
SET @sql = @sql+' order by Count'
EXEC (@sql)