Power BI-Customer purchase count - database

I need to detect the number of customers who make purchases in the 2 stores with a single formula
data:
Result:
1 Person

Create this below measure-
person_count =
var total_shop_count = DISTINCTCOUNT(your_table_name[Shop])
var tab =
SUMMARIZE(
your_table_name,
your_table_name[Name],
"shop_count",DISTINCTCOUNT(your_table_name[Shop])
)
return
COUNTROWS(
FILTER(
tab,
[shop_count] = total_shop_count
)
)
Here is the output-

Related

How to access time in jfree.data

I am trying to access time from jfree.data and adding it to my results table in ImageJ. But this does not work and I don't know why. Here is my code:
// Set IJ settings
ResultsTable rt = new ResultsTable();
// create a series that automatically discard data > 30 seconds old...
TimeSeries intensities = new TimeSeries("Int");
intensities.setMaximumItemAge(30000);
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(intensities);
ImageProcessor ip;
//Run while Live
while (true) {
mm.live().snap(true);
ip = mm.live().getDisplay().getImagePlus().getProcessor();
ImageStatistics stats = ip.getStatistics();
intensities.add(new Millisecond(), stats.mean);
img = images.get(0);
rt.incrementCounter();
rt.addValue("Time",intensities.millisecond);
rt.addValue("Mean",stats.mean);
rt.show("Results");
Thread.sleep(10);
}
What am i doing wrong?
Here is some ImageJ-Java code I use for data entry to an ImageJ-Results table:
ResultsTable table = ResultsTable.getResultsTable( "myTable" );
if ( table == null )
table = new ResultsTable();
else
table.incrementCounter();
table.addValue( "Data", value );
table.show( "myTable" );

How to sum differente source while adding the max date of a source to the others sources

I am confronted with a big dilemma as I am having to figure out how to sum the below case:
Knowing that the expected result is to get the below total.
Your help is sincerely appreciated.
You can create a new Calculated Column using this below DAX code-
SalesAmountsNew =
VAR current_row_date = your_table_name[DayLoadDate]
VAR current_row_surce = your_table_name[Source]
VAR max_date =
CALCULATE(
MAX(your_table_name[DayLoadDate]),
FILTER(
ALL(your_table_name),
your_table_name[Source] = current_row_surce
)
)
RETURN
IF(
max_date = BLANK(),
your_table_name[SalesAmounts],
IF(
current_row_date = max_date,
your_table_name[SalesAmounts],
BLANK()
)
)
Now you can apply sum on that new column SalesAmountsNew

Get click statistics count grouped by month

Been trying to find a proper solution, but have so far been unable to understand or find one properly.
Have the following DB:
I am trying to get the number of clicks in each month.
So i would get something like:
--------------
January - 10
February - 7
March - 22
etc.
This is my code so far:
var MonthlyCount = from c in ClickStatistics
group c.LogDate by new { date = c.LogDate, Id = c.ID }into grp
select new{
Month = grp.Key.date.Month,
Clicks = grp.Key.Id
};
But right now i am just getting this:
Groups items together that have the same c.LogDate.Month. Selects the first item of the group to extract the month as text value (we grouped by month so they should all be equal in that regard) and counts the number of entries in the group.
var ClickStatistics = new List<Clicks>()
{
new Clicks() { ID = 1, LogDate = DateTime.Now.AddMonths(-1)},
new Clicks() { ID = 2, LogDate = DateTime.Now.AddMonths(-1)},
new Clicks() { ID = 3, LogDate = DateTime.Now.AddMonths(0)},
new Clicks() { ID = 4, LogDate = DateTime.Now.AddMonths(0)},
new Clicks() { ID = 5, LogDate = DateTime.Now.AddMonths(1)},
};
var MonthlyCount = from c in ClickStatistics
group c by new { date = c.LogDate.Month } into grp
select new
{
Month = grp.First().LogDate.ToString("MMMM"),
Clicks = grp.Count(),
};

select array value like foreign key way join multiple table

I have table like below
table
CREATE TABLE IF NOT EXISTS "Article"(
"ArticleId" SERIAL NOT NULL,
"GenresIdList" integer[],
...
PRIMARY KEY ("ArticleId")
);
CREATE TABLE IF NOT EXISTS "Tag0"(
"TagId" SERIAL NOT NULL,
"Name" varchar,
...
PRIMARY KEY ("TagId")
);
ArticleId | GenresIdList
1 | {1} |
2 | {1} |
3 | {1,2} |
4 | {1,2,3} |
TagId | Name
1 | hiphop
2 | rock
When user input data inputGenres I want get below result:
if inputGenres = ['hiphop','rock','classical']; then will get no rows in Article
if inputGenres = ['hiphop','rock']; get Article rows 3 and 4
but because I select two table separate then even I use && in select article table when inputGenres = ['hiphop','rock','classical']; when convert to id array I will become [1,2] because there is no classical, then I will get rows 3 and 4.
How to solve this?
ps. I have to design table like this, only store id not store name in 'Article'. so I hope not redesign table
code (with nodejs)
// convert inputGenres to tag0TagIdList
var tag0TagIdList = [];
var db = dbClient;
var query = 'SELECT * FROM "Tag0" WHERE "Name" IN (';
for (var i = 0; i < inputGenres.length; i++) {
if (i > 0) {
query += ',';
}
query += '$' + (i + 1);
}
query += ') ORDER BY "Name" ASC';
var params = inputGenres;
var selectTag0 = yield crudDatabase(db,query,params);
for (var i = 0; i < selectTag0.result.rows.length; i++) {
tag0TagIdList.push(selectTag0.result.rows[i].TagId);
}
// end: convert inputGenres to tag0TagIdList
var db = dbClient;
var query = 'SELECT * FROM "Article" WHERE "GenresIdList" && $1';
var params = [tag0TagIdList];
var selectArticle = yield crudDatabase(db,query,params);
var tag0TagIdList = [];
var db = dbClient;
var query = 'select * from "Article" where "GenresIdList" #> (select array_agg ("TagId") from unnest (array[';
for (var i = 0; i < inputGenres.length; i++) {
if (i > 0) {
query += ',';
}
query += '$' + (i + 1);
}
query += ']) as input_tags left join "Tag0" on ( "Name" = input_tags))';
I don't know java much, but this should return what you want.
query example:
SELECT * FROM "Article"
WHERE
"GenresIdList" #> (
SELECT
array_agg ( "TagId" )
FROM
unnest (ARRAY [ 'hiphop', 'rock' ] ) AS input_tags
LEFT JOIN "Tag0" ON (
"Name" = input_tags ) )

Django Field Choices

Given below is my Model definition and I have added this module part of the Admin. I'm trying to create new row and while selecting value '3' or any other value for Duration field(listed as select fields), I get the following error.- "Value 3 is not a valid choice".
Please provide your inputs.
Model Definition
NO_OF_HRS = (
('1','One'),
('2','Two'),
('3','Three'),
('4','Four'),
('5','Five'),
('6','Six'),
('7','Seven'),
('8','Eight'),
('9','Nine'),
('10','Ten'),
('11','Eleven'),
('12','Twelve'),
)
YR_MONTH = (
("Y", "Year"),
("M", "Month"),
)
POS_STATUS = (
("A", "Active"),
("C", "Closed"),
)
datecreated = models.DateTimeField()
volposition = models.CharField(max_length=300)
roledesc = models.CharField(max_length=5000)
noofhours = models.IntegerField(blank = True,null = True)
Qualreqt = models.CharField(max_length=8000)
Duration = models.IntegerField(choices=NO_OF_HRS,blank = True,null = True)
Durationyrmon = models.CharField(choices=YR_MONTH,max_length=10)
posstatus = models.CharField(choices=POS_STATUS,max_length=1)
teamrelation = models.CharField(max_length=50)
When you use choices, the first value of the tuple is the value that will be stored in the database and the second value is the value that will be shown in the admin.
In NO_OF_HRS the values are strings (for example '1', '2') but it is a models.IntegerField so the values should be integers. That's why you're now getting an error.
Opened a ticket on django with fix and dirty fix:
https://code.djangoproject.com/ticket/24897

Resources